Commit aaa68d2f authored by Takashi Iwai's avatar Takashi Iwai

ALSA: line6: Drop superfluous snd_device for rawmidi

Like the previous fix for PCM, attach the card-specific resource into
rawmidi->private_data instead of handling in a snd_device object.
This simplifies the code and structure.
Tested-by: default avatarChris Rorvick <chris@rorvick.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent b45a7c56
...@@ -223,28 +223,20 @@ static struct snd_rawmidi_ops line6_midi_input_ops = { ...@@ -223,28 +223,20 @@ static struct snd_rawmidi_ops line6_midi_input_ops = {
.trigger = line6_midi_input_trigger, .trigger = line6_midi_input_trigger,
}; };
/*
Cleanup the Line6 MIDI device.
*/
static void line6_cleanup_midi(struct snd_rawmidi *rmidi)
{
}
/* Create a MIDI device */ /* Create a MIDI device */
static int snd_line6_new_midi(struct snd_line6_midi *line6midi) static int snd_line6_new_midi(struct usb_line6 *line6,
struct snd_rawmidi **rmidi_ret)
{ {
struct snd_rawmidi *rmidi; struct snd_rawmidi *rmidi;
int err; int err;
err = snd_rawmidi_new(line6midi->line6->card, "Line6 MIDI", 0, 1, 1, err = snd_rawmidi_new(line6->card, "Line6 MIDI", 0, 1, 1, rmidi_ret);
&rmidi);
if (err < 0) if (err < 0)
return err; return err;
rmidi->private_data = line6midi; rmidi = *rmidi_ret;
rmidi->private_free = line6_cleanup_midi; strcpy(rmidi->id, line6->properties->id);
strcpy(rmidi->id, line6midi->line6->properties->id); strcpy(rmidi->name, line6->properties->name);
strcpy(rmidi->name, line6midi->line6->properties->name);
rmidi->info_flags = rmidi->info_flags =
SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_OUTPUT |
...@@ -258,13 +250,13 @@ static int snd_line6_new_midi(struct snd_line6_midi *line6midi) ...@@ -258,13 +250,13 @@ static int snd_line6_new_midi(struct snd_line6_midi *line6midi)
} }
/* MIDI device destructor */ /* MIDI device destructor */
static int snd_line6_midi_free(struct snd_device *device) static void snd_line6_midi_free(struct snd_rawmidi *rmidi)
{ {
struct snd_line6_midi *line6midi = device->device_data; struct snd_line6_midi *line6midi = rmidi->private_data;
line6_midibuf_destroy(&line6midi->midibuf_in); line6_midibuf_destroy(&line6midi->midibuf_in);
line6_midibuf_destroy(&line6midi->midibuf_out); line6_midibuf_destroy(&line6midi->midibuf_out);
return 0; kfree(line6midi);
} }
/* /*
...@@ -272,11 +264,8 @@ static int snd_line6_midi_free(struct snd_device *device) ...@@ -272,11 +264,8 @@ static int snd_line6_midi_free(struct snd_device *device)
*/ */
int line6_init_midi(struct usb_line6 *line6) int line6_init_midi(struct usb_line6 *line6)
{ {
static struct snd_device_ops midi_ops = {
.dev_free = snd_line6_midi_free,
};
int err; int err;
struct snd_rawmidi *rmidi;
struct snd_line6_midi *line6midi; struct snd_line6_midi *line6midi;
if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) { if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) {
...@@ -284,39 +273,31 @@ int line6_init_midi(struct usb_line6 *line6) ...@@ -284,39 +273,31 @@ int line6_init_midi(struct usb_line6 *line6)
return 0; return 0;
} }
line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL); err = snd_line6_new_midi(line6, &rmidi);
if (err < 0)
return err;
if (line6midi == NULL) line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL);
if (!line6midi)
return -ENOMEM; return -ENOMEM;
err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0); rmidi->private_data = line6midi;
if (err < 0) { rmidi->private_free = snd_line6_midi_free;
kfree(line6midi);
return err;
}
err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
if (err < 0) {
kfree(line6midi->midibuf_in.buf);
kfree(line6midi);
return err;
}
init_waitqueue_head(&line6midi->send_wait);
spin_lock_init(&line6midi->send_urb_lock);
spin_lock_init(&line6midi->midi_transmit_lock);
line6midi->line6 = line6; line6midi->line6 = line6;
line6->line6midi = line6midi;
err = snd_device_new(line6->card, SNDRV_DEV_RAWMIDI, line6midi, err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
&midi_ops);
if (err < 0) if (err < 0)
return err; return err;
err = snd_line6_new_midi(line6midi); err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
if (err < 0) if (err < 0)
return err; return err;
init_waitqueue_head(&line6midi->send_wait); line6->line6midi = line6midi;
spin_lock_init(&line6midi->send_urb_lock);
spin_lock_init(&line6midi->midi_transmit_lock);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(line6_init_midi); EXPORT_SYMBOL_GPL(line6_init_midi);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment