aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-01-19 08:50:31 -0500
committerTakashi Iwai <tiwai@suse.de>2015-01-20 02:15:02 -0500
commitaaa68d2f295147a7b648bbab632557c7429fb8cd (patch)
treec4495febad427c142bd9467a002fdc09605964cb /sound/usb
parentb45a7c565473d29bd7e02ac8ca86232a24ca247f (diff)
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>
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/line6/midi.c65
1 files changed, 23 insertions, 42 deletions
diff --git a/sound/usb/line6/midi.c b/sound/usb/line6/midi.c
index 2a42d533f49c..ebca5ebcfecc 100644
--- a/sound/usb/line6/midi.c
+++ b/sound/usb/line6/midi.c
@@ -223,28 +223,20 @@ static struct snd_rawmidi_ops line6_midi_input_ops = {
223 .trigger = line6_midi_input_trigger, 223 .trigger = line6_midi_input_trigger,
224}; 224};
225 225
226/*
227 Cleanup the Line6 MIDI device.
228*/
229static void line6_cleanup_midi(struct snd_rawmidi *rmidi)
230{
231}
232
233/* Create a MIDI device */ 226/* Create a MIDI device */
234static int snd_line6_new_midi(struct snd_line6_midi *line6midi) 227static int snd_line6_new_midi(struct usb_line6 *line6,
228 struct snd_rawmidi **rmidi_ret)
235{ 229{
236 struct snd_rawmidi *rmidi; 230 struct snd_rawmidi *rmidi;
237 int err; 231 int err;
238 232
239 err = snd_rawmidi_new(line6midi->line6->card, "Line6 MIDI", 0, 1, 1, 233 err = snd_rawmidi_new(line6->card, "Line6 MIDI", 0, 1, 1, rmidi_ret);
240 &rmidi);
241 if (err < 0) 234 if (err < 0)
242 return err; 235 return err;
243 236
244 rmidi->private_data = line6midi; 237 rmidi = *rmidi_ret;
245 rmidi->private_free = line6_cleanup_midi; 238 strcpy(rmidi->id, line6->properties->id);
246 strcpy(rmidi->id, line6midi->line6->properties->id); 239 strcpy(rmidi->name, line6->properties->name);
247 strcpy(rmidi->name, line6midi->line6->properties->name);
248 240
249 rmidi->info_flags = 241 rmidi->info_flags =
250 SNDRV_RAWMIDI_INFO_OUTPUT | 242 SNDRV_RAWMIDI_INFO_OUTPUT |
@@ -258,13 +250,13 @@ static int snd_line6_new_midi(struct snd_line6_midi *line6midi)
258} 250}
259 251
260/* MIDI device destructor */ 252/* MIDI device destructor */
261static int snd_line6_midi_free(struct snd_device *device) 253static void snd_line6_midi_free(struct snd_rawmidi *rmidi)
262{ 254{
263 struct snd_line6_midi *line6midi = device->device_data; 255 struct snd_line6_midi *line6midi = rmidi->private_data;
264 256
265 line6_midibuf_destroy(&line6midi->midibuf_in); 257 line6_midibuf_destroy(&line6midi->midibuf_in);
266 line6_midibuf_destroy(&line6midi->midibuf_out); 258 line6_midibuf_destroy(&line6midi->midibuf_out);
267 return 0; 259 kfree(line6midi);
268} 260}
269 261
270/* 262/*
@@ -272,11 +264,8 @@ static int snd_line6_midi_free(struct snd_device *device)
272*/ 264*/
273int line6_init_midi(struct usb_line6 *line6) 265int line6_init_midi(struct usb_line6 *line6)
274{ 266{
275 static struct snd_device_ops midi_ops = {
276 .dev_free = snd_line6_midi_free,
277 };
278
279 int err; 267 int err;
268 struct snd_rawmidi *rmidi;
280 struct snd_line6_midi *line6midi; 269 struct snd_line6_midi *line6midi;
281 270
282 if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) { 271 if (!(line6->properties->capabilities & LINE6_CAP_CONTROL)) {
@@ -284,39 +273,31 @@ int line6_init_midi(struct usb_line6 *line6)
284 return 0; 273 return 0;
285 } 274 }
286 275
287 line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL); 276 err = snd_line6_new_midi(line6, &rmidi);
277 if (err < 0)
278 return err;
288 279
289 if (line6midi == NULL) 280 line6midi = kzalloc(sizeof(struct snd_line6_midi), GFP_KERNEL);
281 if (!line6midi)
290 return -ENOMEM; 282 return -ENOMEM;
291 283
292 err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0); 284 rmidi->private_data = line6midi;
293 if (err < 0) { 285 rmidi->private_free = snd_line6_midi_free;
294 kfree(line6midi);
295 return err;
296 }
297
298 err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
299 if (err < 0) {
300 kfree(line6midi->midibuf_in.buf);
301 kfree(line6midi);
302 return err;
303 }
304 286
287 init_waitqueue_head(&line6midi->send_wait);
288 spin_lock_init(&line6midi->send_urb_lock);
289 spin_lock_init(&line6midi->midi_transmit_lock);
305 line6midi->line6 = line6; 290 line6midi->line6 = line6;
306 line6->line6midi = line6midi;
307 291
308 err = snd_device_new(line6->card, SNDRV_DEV_RAWMIDI, line6midi, 292 err = line6_midibuf_init(&line6midi->midibuf_in, MIDI_BUFFER_SIZE, 0);
309 &midi_ops);
310 if (err < 0) 293 if (err < 0)
311 return err; 294 return err;
312 295
313 err = snd_line6_new_midi(line6midi); 296 err = line6_midibuf_init(&line6midi->midibuf_out, MIDI_BUFFER_SIZE, 1);
314 if (err < 0) 297 if (err < 0)
315 return err; 298 return err;
316 299
317 init_waitqueue_head(&line6midi->send_wait); 300 line6->line6midi = line6midi;
318 spin_lock_init(&line6midi->send_urb_lock);
319 spin_lock_init(&line6midi->midi_transmit_lock);
320 return 0; 301 return 0;
321} 302}
322EXPORT_SYMBOL_GPL(line6_init_midi); 303EXPORT_SYMBOL_GPL(line6_init_midi);