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: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2015-01-19 14:50:31 +01:00
parent b45a7c5654
commit aaa68d2f29

View File

@ -223,28 +223,20 @@ static struct snd_rawmidi_ops line6_midi_input_ops = {
.trigger = line6_midi_input_trigger,
};
/*
Cleanup the Line6 MIDI device.
*/
static void line6_cleanup_midi(struct snd_rawmidi *rmidi)
{
}
/* 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;
int err;
err = snd_rawmidi_new(line6midi->line6->card, "Line6 MIDI", 0, 1, 1,
&rmidi);
err = snd_rawmidi_new(line6->card, "Line6 MIDI", 0, 1, 1, rmidi_ret);
if (err < 0)
return err;
rmidi->private_data = line6midi;
rmidi->private_free = line6_cleanup_midi;
strcpy(rmidi->id, line6midi->line6->properties->id);
strcpy(rmidi->name, line6midi->line6->properties->name);
rmidi = *rmidi_ret;
strcpy(rmidi->id, line6->properties->id);
strcpy(rmidi->name, line6->properties->name);
rmidi->info_flags =
SNDRV_RAWMIDI_INFO_OUTPUT |
@ -258,13 +250,13 @@ static int snd_line6_new_midi(struct snd_line6_midi *line6midi)
}
/* 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_out);
return 0;
kfree(line6midi);
}
/*
@ -272,11 +264,8 @@ static int snd_line6_midi_free(struct snd_device *device)
*/
int line6_init_midi(struct usb_line6 *line6)
{
static struct snd_device_ops midi_ops = {
.dev_free = snd_line6_midi_free,
};
int err;
struct snd_rawmidi *rmidi;
struct snd_line6_midi *line6midi;
if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) {
@ -284,39 +273,31 @@ int line6_init_midi(struct usb_line6 *line6)
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;
err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
if (err < 0) {
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;
}
line6midi->line6 = line6;
line6->line6midi = line6midi;
err = snd_device_new(line6->card, SNDRV_DEV_RAWMIDI, line6midi,
&midi_ops);
if (err < 0)
return err;
err = snd_line6_new_midi(line6midi);
if (err < 0)
return err;
rmidi->private_data = line6midi;
rmidi->private_free = snd_line6_midi_free;
init_waitqueue_head(&line6midi->send_wait);
spin_lock_init(&line6midi->send_urb_lock);
spin_lock_init(&line6midi->midi_transmit_lock);
line6midi->line6 = line6;
err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
if (err < 0)
return err;
err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
if (err < 0)
return err;
line6->line6midi = line6midi;
return 0;
}
EXPORT_SYMBOL_GPL(line6_init_midi);