Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: rawmidi: Don't embed device

This patch detaches the struct device from the snd_rawmidi object by
allocating via snd_device_alloc(), just like done for other devices.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
Tested-by: Curtis Malainey <cujomalainey@chromium.org>
Link: https://lore.kernel.org/r/20230816160252.23396-6-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+18 -21
+1 -1
include/sound/rawmidi.h
··· 135 135 struct mutex open_mutex; 136 136 wait_queue_head_t open_wait; 137 137 138 - struct device dev; 138 + struct device *dev; 139 139 140 140 struct snd_info_entry *proc_entry; 141 141
+13 -16
sound/core/rawmidi.c
··· 44 44 static DEFINE_MUTEX(register_mutex); 45 45 46 46 #define rmidi_err(rmidi, fmt, args...) \ 47 - dev_err(&(rmidi)->dev, fmt, ##args) 47 + dev_err((rmidi)->dev, fmt, ##args) 48 48 #define rmidi_warn(rmidi, fmt, args...) \ 49 - dev_warn(&(rmidi)->dev, fmt, ##args) 49 + dev_warn((rmidi)->dev, fmt, ##args) 50 50 #define rmidi_dbg(rmidi, fmt, args...) \ 51 - dev_dbg(&(rmidi)->dev, fmt, ##args) 51 + dev_dbg((rmidi)->dev, fmt, ##args) 52 52 53 53 struct snd_rawmidi_status32 { 54 54 s32 stream; ··· 1877 1877 return 0; 1878 1878 } 1879 1879 1880 - static void release_rawmidi_device(struct device *dev) 1881 - { 1882 - kfree(container_of(dev, struct snd_rawmidi, dev)); 1883 - } 1884 - 1885 1880 /* used for both rawmidi and ump */ 1886 1881 int snd_rawmidi_init(struct snd_rawmidi *rmidi, 1887 1882 struct snd_card *card, char *id, int device, ··· 1901 1906 if (id != NULL) 1902 1907 strscpy(rmidi->id, id, sizeof(rmidi->id)); 1903 1908 1904 - snd_device_initialize(&rmidi->dev, card); 1905 - rmidi->dev.release = release_rawmidi_device; 1909 + err = snd_device_alloc(&rmidi->dev, card); 1910 + if (err < 0) 1911 + return err; 1906 1912 if (rawmidi_is_ump(rmidi)) 1907 - dev_set_name(&rmidi->dev, "umpC%iD%i", card->number, device); 1913 + dev_set_name(rmidi->dev, "umpC%iD%i", card->number, device); 1908 1914 else 1909 - dev_set_name(&rmidi->dev, "midiC%iD%i", card->number, device); 1915 + dev_set_name(rmidi->dev, "midiC%iD%i", card->number, device); 1910 1916 1911 1917 err = snd_rawmidi_alloc_substreams(rmidi, 1912 1918 &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], ··· 1992 1996 snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); 1993 1997 if (rmidi->private_free) 1994 1998 rmidi->private_free(rmidi); 1995 - put_device(&rmidi->dev); 1999 + put_device(rmidi->dev); 2000 + kfree(rmidi); 1996 2001 return 0; 1997 2002 } 1998 2003 EXPORT_SYMBOL_GPL(snd_rawmidi_free); ··· 2035 2038 2036 2039 err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, 2037 2040 rmidi->card, rmidi->device, 2038 - &snd_rawmidi_f_ops, rmidi, &rmidi->dev); 2041 + &snd_rawmidi_f_ops, rmidi, rmidi->dev); 2039 2042 if (err < 0) { 2040 2043 rmidi_err(rmidi, "unable to register\n"); 2041 2044 goto error; ··· 2100 2103 return 0; 2101 2104 2102 2105 error_unregister: 2103 - snd_unregister_device(&rmidi->dev); 2106 + snd_unregister_device(rmidi->dev); 2104 2107 error: 2105 2108 mutex_lock(&register_mutex); 2106 2109 list_del(&rmidi->list); ··· 2139 2142 rmidi->ossreg = 0; 2140 2143 } 2141 2144 #endif /* CONFIG_SND_OSSEMUL */ 2142 - snd_unregister_device(&rmidi->dev); 2145 + snd_unregister_device(rmidi->dev); 2143 2146 mutex_unlock(&rmidi->open_mutex); 2144 2147 mutex_unlock(&register_mutex); 2145 2148 return 0;
+4 -4
sound/core/ump.c
··· 13 13 #include <sound/ump.h> 14 14 #include <sound/ump_convert.h> 15 15 16 - #define ump_err(ump, fmt, args...) dev_err(&(ump)->core.dev, fmt, ##args) 17 - #define ump_warn(ump, fmt, args...) dev_warn(&(ump)->core.dev, fmt, ##args) 18 - #define ump_info(ump, fmt, args...) dev_info(&(ump)->core.dev, fmt, ##args) 19 - #define ump_dbg(ump, fmt, args...) dev_dbg(&(ump)->core.dev, fmt, ##args) 16 + #define ump_err(ump, fmt, args...) dev_err((ump)->core.dev, fmt, ##args) 17 + #define ump_warn(ump, fmt, args...) dev_warn((ump)->core.dev, fmt, ##args) 18 + #define ump_info(ump, fmt, args...) dev_info((ump)->core.dev, fmt, ##args) 19 + #define ump_dbg(ump, fmt, args...) dev_dbg((ump)->core.dev, fmt, ##args) 20 20 21 21 static int snd_ump_dev_register(struct snd_rawmidi *rmidi); 22 22 static int snd_ump_dev_unregister(struct snd_rawmidi *rmidi);