ALSA: rawmidi: Embed struct device
Like previous patches, this changes the device management for rawmidi, embedding the struct device into struct snd_rawmidi. The required change is more or less same as hwdep device. The currently unused dev field is reused as the new embedded struct field now. Reviewed-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
@ -28,6 +28,7 @@
|
|||||||
#include <linux/wait.h>
|
#include <linux/wait.h>
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
|
#include <linux/device.h>
|
||||||
|
|
||||||
#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
|
#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
|
||||||
#include <sound/seq_device.h>
|
#include <sound/seq_device.h>
|
||||||
@ -139,7 +140,8 @@ struct snd_rawmidi {
|
|||||||
struct mutex open_mutex;
|
struct mutex open_mutex;
|
||||||
wait_queue_head_t open_wait;
|
wait_queue_head_t open_wait;
|
||||||
|
|
||||||
struct snd_info_entry *dev;
|
struct device dev;
|
||||||
|
|
||||||
struct snd_info_entry *proc_entry;
|
struct snd_info_entry *proc_entry;
|
||||||
|
|
||||||
#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
|
#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
|
||||||
|
@ -1443,6 +1443,11 @@ 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));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* snd_rawmidi_new - create a rawmidi instance
|
* snd_rawmidi_new - create a rawmidi instance
|
||||||
* @card: the card instance
|
* @card: the card instance
|
||||||
@ -1487,6 +1492,11 @@ int snd_rawmidi_new(struct snd_card *card, char *id, int device,
|
|||||||
|
|
||||||
if (id != NULL)
|
if (id != NULL)
|
||||||
strlcpy(rmidi->id, id, sizeof(rmidi->id));
|
strlcpy(rmidi->id, id, sizeof(rmidi->id));
|
||||||
|
|
||||||
|
snd_device_initialize(&rmidi->dev, card);
|
||||||
|
rmidi->dev.release = release_rawmidi_device;
|
||||||
|
dev_set_name(&rmidi->dev, "midiC%iD%i", card->number, device);
|
||||||
|
|
||||||
if ((err = snd_rawmidi_alloc_substreams(rmidi,
|
if ((err = snd_rawmidi_alloc_substreams(rmidi,
|
||||||
&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
|
&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT],
|
||||||
SNDRV_RAWMIDI_STREAM_INPUT,
|
SNDRV_RAWMIDI_STREAM_INPUT,
|
||||||
@ -1538,7 +1548,7 @@ static 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);
|
||||||
kfree(rmidi);
|
put_device(&rmidi->dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1571,12 +1581,12 @@ static int snd_rawmidi_dev_register(struct snd_device *device)
|
|||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
list_add_tail(&rmidi->list, &snd_rawmidi_devices);
|
list_add_tail(&rmidi->list, &snd_rawmidi_devices);
|
||||||
sprintf(name, "midiC%iD%i", rmidi->card->number, rmidi->device);
|
err = snd_register_device_for_dev(SNDRV_DEVICE_TYPE_RAWMIDI,
|
||||||
if ((err = snd_register_device(SNDRV_DEVICE_TYPE_RAWMIDI,
|
rmidi->card, rmidi->device,
|
||||||
rmidi->card, rmidi->device,
|
&snd_rawmidi_f_ops, rmidi,
|
||||||
&snd_rawmidi_f_ops, rmidi, name)) < 0) {
|
&rmidi->dev, NULL, NULL);
|
||||||
rmidi_err(rmidi, "unable to register rawmidi device %i:%i\n",
|
if (err < 0) {
|
||||||
rmidi->card->number, rmidi->device);
|
rmidi_err(rmidi, "unable to register\n");
|
||||||
list_del(&rmidi->list);
|
list_del(&rmidi->list);
|
||||||
mutex_unlock(®ister_mutex);
|
mutex_unlock(®ister_mutex);
|
||||||
return err;
|
return err;
|
||||||
|
Reference in New Issue
Block a user