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>
This commit is contained in:
Takashi Iwai 2023-08-16 18:02:48 +02:00
parent 897c8882df
commit ea29a02fd8
3 changed files with 18 additions and 21 deletions

View File

@ -135,7 +135,7 @@ struct snd_rawmidi {
struct mutex open_mutex; struct mutex open_mutex;
wait_queue_head_t open_wait; wait_queue_head_t open_wait;
struct device dev; struct device *dev;
struct snd_info_entry *proc_entry; struct snd_info_entry *proc_entry;

View File

@ -44,11 +44,11 @@ static LIST_HEAD(snd_rawmidi_devices);
static DEFINE_MUTEX(register_mutex); static DEFINE_MUTEX(register_mutex);
#define rmidi_err(rmidi, fmt, args...) \ #define rmidi_err(rmidi, fmt, args...) \
dev_err(&(rmidi)->dev, fmt, ##args) dev_err((rmidi)->dev, fmt, ##args)
#define rmidi_warn(rmidi, fmt, args...) \ #define rmidi_warn(rmidi, fmt, args...) \
dev_warn(&(rmidi)->dev, fmt, ##args) dev_warn((rmidi)->dev, fmt, ##args)
#define rmidi_dbg(rmidi, fmt, args...) \ #define rmidi_dbg(rmidi, fmt, args...) \
dev_dbg(&(rmidi)->dev, fmt, ##args) dev_dbg((rmidi)->dev, fmt, ##args)
struct snd_rawmidi_status32 { struct snd_rawmidi_status32 {
s32 stream; s32 stream;
@ -1877,11 +1877,6 @@ static int snd_rawmidi_alloc_substreams(struct snd_rawmidi *rmidi,
return 0; return 0;
} }
static void release_rawmidi_device(struct device *dev)
{
kfree(container_of(dev, struct snd_rawmidi, dev));
}
/* used for both rawmidi and ump */ /* used for both rawmidi and ump */
int snd_rawmidi_init(struct snd_rawmidi *rmidi, int snd_rawmidi_init(struct snd_rawmidi *rmidi,
struct snd_card *card, char *id, int device, struct snd_card *card, char *id, int device,
@ -1906,12 +1901,13 @@ int snd_rawmidi_init(struct snd_rawmidi *rmidi,
if (id != NULL) if (id != NULL)
strscpy(rmidi->id, id, sizeof(rmidi->id)); strscpy(rmidi->id, id, sizeof(rmidi->id));
snd_device_initialize(&rmidi->dev, card); err = snd_device_alloc(&rmidi->dev, card);
rmidi->dev.release = release_rawmidi_device; if (err < 0)
return err;
if (rawmidi_is_ump(rmidi)) if (rawmidi_is_ump(rmidi))
dev_set_name(&rmidi->dev, "umpC%iD%i", card->number, device); dev_set_name(rmidi->dev, "umpC%iD%i", card->number, device);
else else
dev_set_name(&rmidi->dev, "midiC%iD%i", card->number, device); dev_set_name(rmidi->dev, "midiC%iD%i", card->number, device);
err = snd_rawmidi_alloc_substreams(rmidi, err = snd_rawmidi_alloc_substreams(rmidi,
&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT], &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
@ -1996,7 +1992,8 @@ int snd_rawmidi_free(struct snd_rawmidi *rmidi)
snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]); snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);
if (rmidi->private_free) if (rmidi->private_free)
rmidi->private_free(rmidi); rmidi->private_free(rmidi);
put_device(&rmidi->dev); put_device(rmidi->dev);
kfree(rmidi);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(snd_rawmidi_free); EXPORT_SYMBOL_GPL(snd_rawmidi_free);
@ -2038,7 +2035,7 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI, err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
rmidi->card, rmidi->device, rmidi->card, rmidi->device,
&snd_rawmidi_f_ops, rmidi, &rmidi->dev); &snd_rawmidi_f_ops, rmidi, rmidi->dev);
if (err < 0) { if (err < 0) {
rmidi_err(rmidi, "unable to register\n"); rmidi_err(rmidi, "unable to register\n");
goto error; goto error;
@ -2103,7 +2100,7 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
return 0; return 0;
error_unregister: error_unregister:
snd_unregister_device(&rmidi->dev); snd_unregister_device(rmidi->dev);
error: error:
mutex_lock(&register_mutex); mutex_lock(&register_mutex);
list_del(&rmidi->list); list_del(&rmidi->list);
@ -2142,7 +2139,7 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device)
rmidi->ossreg = 0; rmidi->ossreg = 0;
} }
#endif /* CONFIG_SND_OSSEMUL */ #endif /* CONFIG_SND_OSSEMUL */
snd_unregister_device(&rmidi->dev); snd_unregister_device(rmidi->dev);
mutex_unlock(&rmidi->open_mutex); mutex_unlock(&rmidi->open_mutex);
mutex_unlock(&register_mutex); mutex_unlock(&register_mutex);
return 0; return 0;

View File

@ -13,10 +13,10 @@
#include <sound/ump.h> #include <sound/ump.h>
#include <sound/ump_convert.h> #include <sound/ump_convert.h>
#define ump_err(ump, fmt, args...) dev_err(&(ump)->core.dev, fmt, ##args) #define ump_err(ump, fmt, args...) dev_err((ump)->core.dev, fmt, ##args)
#define ump_warn(ump, fmt, args...) dev_warn(&(ump)->core.dev, fmt, ##args) #define ump_warn(ump, fmt, args...) dev_warn((ump)->core.dev, fmt, ##args)
#define ump_info(ump, fmt, args...) dev_info(&(ump)->core.dev, fmt, ##args) #define ump_info(ump, fmt, args...) dev_info((ump)->core.dev, fmt, ##args)
#define ump_dbg(ump, fmt, args...) dev_dbg(&(ump)->core.dev, fmt, ##args) #define ump_dbg(ump, fmt, args...) dev_dbg((ump)->core.dev, fmt, ##args)
static int snd_ump_dev_register(struct snd_rawmidi *rmidi); static int snd_ump_dev_register(struct snd_rawmidi *rmidi);
static int snd_ump_dev_unregister(struct snd_rawmidi *rmidi); static int snd_ump_dev_unregister(struct snd_rawmidi *rmidi);