diff options
author | Takashi Iwai <tiwai@suse.de> | 2015-01-25 12:36:29 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2015-01-28 01:22:07 -0500 |
commit | aca514b82356dcc3575da33453382bd27593aea1 (patch) | |
tree | ccb08ee0c6142b905382df6d192375e5f53d257c /sound/usb/line6 | |
parent | f66fd990c5db177d6b9f0eae301ca6b15882eb2e (diff) |
ALSA: line6: Let snd_card_new() allocate private data
Instead of allocating the private data individually in each driver's
probe at first, let snd_card_new() allocate the data that is called in
line6_probe(). This simplifies the primary probe functions.
Tested-by: Chris Rorvick <chris@rorvick.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/line6')
-rw-r--r-- | sound/usb/line6/driver.c | 25 | ||||
-rw-r--r-- | sound/usb/line6/driver.h | 4 | ||||
-rw-r--r-- | sound/usb/line6/pod.c | 9 | ||||
-rw-r--r-- | sound/usb/line6/podhd.c | 9 | ||||
-rw-r--r-- | sound/usb/line6/toneport.c | 9 | ||||
-rw-r--r-- | sound/usb/line6/variax.c | 9 |
6 files changed, 20 insertions, 45 deletions
diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c index e2fbff05c1b1..c696f9773cbb 100644 --- a/sound/usb/line6/driver.c +++ b/sound/usb/line6/driver.c | |||
@@ -418,11 +418,7 @@ EXPORT_SYMBOL_GPL(line6_read_serial_number); | |||
418 | static void line6_destruct(struct snd_card *card) | 418 | static void line6_destruct(struct snd_card *card) |
419 | { | 419 | { |
420 | struct usb_line6 *line6 = card->private_data; | 420 | struct usb_line6 *line6 = card->private_data; |
421 | struct usb_device *usbdev; | 421 | struct usb_device *usbdev = line6->usbdev; |
422 | |||
423 | if (!line6) | ||
424 | return; | ||
425 | usbdev = line6->usbdev; | ||
426 | 422 | ||
427 | /* free buffer memory first: */ | 423 | /* free buffer memory first: */ |
428 | kfree(line6->buffer_message); | 424 | kfree(line6->buffer_message); |
@@ -431,9 +427,6 @@ static void line6_destruct(struct snd_card *card) | |||
431 | /* then free URBs: */ | 427 | /* then free URBs: */ |
432 | usb_free_urb(line6->urb_listen); | 428 | usb_free_urb(line6->urb_listen); |
433 | 429 | ||
434 | /* free interface data: */ | ||
435 | kfree(line6); | ||
436 | |||
437 | /* decrement reference counters: */ | 430 | /* decrement reference counters: */ |
438 | usb_put_dev(usbdev); | 431 | usb_put_dev(usbdev); |
439 | } | 432 | } |
@@ -489,24 +482,27 @@ static int line6_init_cap_control(struct usb_line6 *line6) | |||
489 | */ | 482 | */ |
490 | int line6_probe(struct usb_interface *interface, | 483 | int line6_probe(struct usb_interface *interface, |
491 | const struct usb_device_id *id, | 484 | const struct usb_device_id *id, |
492 | struct usb_line6 *line6, | ||
493 | const struct line6_properties *properties, | 485 | const struct line6_properties *properties, |
494 | int (*private_init)(struct usb_line6 *, const struct usb_device_id *id)) | 486 | int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), |
487 | size_t data_size) | ||
495 | { | 488 | { |
496 | struct usb_device *usbdev = interface_to_usbdev(interface); | 489 | struct usb_device *usbdev = interface_to_usbdev(interface); |
497 | struct snd_card *card; | 490 | struct snd_card *card; |
491 | struct usb_line6 *line6; | ||
498 | int interface_number; | 492 | int interface_number; |
499 | int ret; | 493 | int ret; |
500 | 494 | ||
495 | if (WARN_ON(data_size < sizeof(*line6))) | ||
496 | return -EINVAL; | ||
497 | |||
501 | ret = snd_card_new(&interface->dev, | 498 | ret = snd_card_new(&interface->dev, |
502 | SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, | 499 | SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, |
503 | THIS_MODULE, 0, &card); | 500 | THIS_MODULE, data_size, &card); |
504 | if (ret < 0) { | 501 | if (ret < 0) |
505 | kfree(line6); | ||
506 | return ret; | 502 | return ret; |
507 | } | ||
508 | 503 | ||
509 | /* store basic data: */ | 504 | /* store basic data: */ |
505 | line6 = card->private_data; | ||
510 | line6->card = card; | 506 | line6->card = card; |
511 | line6->properties = properties; | 507 | line6->properties = properties; |
512 | line6->usbdev = usbdev; | 508 | line6->usbdev = usbdev; |
@@ -517,7 +513,6 @@ int line6_probe(struct usb_interface *interface, | |||
517 | strcpy(card->shortname, line6->properties->name); | 513 | strcpy(card->shortname, line6->properties->name); |
518 | sprintf(card->longname, "Line 6 %s at USB %s", line6->properties->name, | 514 | sprintf(card->longname, "Line 6 %s at USB %s", line6->properties->name, |
519 | dev_name(line6->ifcdev)); | 515 | dev_name(line6->ifcdev)); |
520 | card->private_data = line6; | ||
521 | card->private_free = line6_destruct; | 516 | card->private_free = line6_destruct; |
522 | 517 | ||
523 | usb_set_intfdata(interface, line6); | 518 | usb_set_intfdata(interface, line6); |
diff --git a/sound/usb/line6/driver.h b/sound/usb/line6/driver.h index 4dc6c28e8224..fce10f12f0d3 100644 --- a/sound/usb/line6/driver.h +++ b/sound/usb/line6/driver.h | |||
@@ -181,9 +181,9 @@ extern int line6_write_data(struct usb_line6 *line6, int address, void *data, | |||
181 | 181 | ||
182 | int line6_probe(struct usb_interface *interface, | 182 | int line6_probe(struct usb_interface *interface, |
183 | const struct usb_device_id *id, | 183 | const struct usb_device_id *id, |
184 | struct usb_line6 *line6, | ||
185 | const struct line6_properties *properties, | 184 | const struct line6_properties *properties, |
186 | int (*private_init)(struct usb_line6 *, const struct usb_device_id *id)); | 185 | int (*private_init)(struct usb_line6 *, const struct usb_device_id *id), |
186 | size_t data_size); | ||
187 | 187 | ||
188 | void line6_disconnect(struct usb_interface *interface); | 188 | void line6_disconnect(struct usb_interface *interface); |
189 | 189 | ||
diff --git a/sound/usb/line6/pod.c b/sound/usb/line6/pod.c index d1e952fbcae7..6f7cd585f2d8 100644 --- a/sound/usb/line6/pod.c +++ b/sound/usb/line6/pod.c | |||
@@ -591,14 +591,9 @@ static const struct line6_properties pod_properties_table[] = { | |||
591 | static int pod_probe(struct usb_interface *interface, | 591 | static int pod_probe(struct usb_interface *interface, |
592 | const struct usb_device_id *id) | 592 | const struct usb_device_id *id) |
593 | { | 593 | { |
594 | struct usb_line6_pod *pod; | 594 | return line6_probe(interface, id, |
595 | |||
596 | pod = kzalloc(sizeof(*pod), GFP_KERNEL); | ||
597 | if (!pod) | ||
598 | return -ENODEV; | ||
599 | return line6_probe(interface, id, &pod->line6, | ||
600 | &pod_properties_table[id->driver_info], | 595 | &pod_properties_table[id->driver_info], |
601 | pod_init); | 596 | pod_init, sizeof(struct usb_line6_pod)); |
602 | } | 597 | } |
603 | 598 | ||
604 | static struct usb_driver pod_driver = { | 599 | static struct usb_driver pod_driver = { |
diff --git a/sound/usb/line6/podhd.c b/sound/usb/line6/podhd.c index 21d7edcfa272..43c39886597e 100644 --- a/sound/usb/line6/podhd.c +++ b/sound/usb/line6/podhd.c | |||
@@ -177,14 +177,9 @@ static const struct line6_properties podhd_properties_table[] = { | |||
177 | static int podhd_probe(struct usb_interface *interface, | 177 | static int podhd_probe(struct usb_interface *interface, |
178 | const struct usb_device_id *id) | 178 | const struct usb_device_id *id) |
179 | { | 179 | { |
180 | struct usb_line6_podhd *podhd; | 180 | return line6_probe(interface, id, |
181 | |||
182 | podhd = kzalloc(sizeof(*podhd), GFP_KERNEL); | ||
183 | if (!podhd) | ||
184 | return -ENODEV; | ||
185 | return line6_probe(interface, id, &podhd->line6, | ||
186 | &podhd_properties_table[id->driver_info], | 181 | &podhd_properties_table[id->driver_info], |
187 | podhd_init); | 182 | podhd_init, sizeof(struct usb_line6_podhd)); |
188 | } | 183 | } |
189 | 184 | ||
190 | static struct usb_driver podhd_driver = { | 185 | static struct usb_driver podhd_driver = { |
diff --git a/sound/usb/line6/toneport.c b/sound/usb/line6/toneport.c index 8e7020df0d10..33d16ecf18a0 100644 --- a/sound/usb/line6/toneport.c +++ b/sound/usb/line6/toneport.c | |||
@@ -558,14 +558,9 @@ static const struct line6_properties toneport_properties_table[] = { | |||
558 | static int toneport_probe(struct usb_interface *interface, | 558 | static int toneport_probe(struct usb_interface *interface, |
559 | const struct usb_device_id *id) | 559 | const struct usb_device_id *id) |
560 | { | 560 | { |
561 | struct usb_line6_toneport *toneport; | 561 | return line6_probe(interface, id, |
562 | |||
563 | toneport = kzalloc(sizeof(*toneport), GFP_KERNEL); | ||
564 | if (!toneport) | ||
565 | return -ENODEV; | ||
566 | return line6_probe(interface, id, &toneport->line6, | ||
567 | &toneport_properties_table[id->driver_info], | 562 | &toneport_properties_table[id->driver_info], |
568 | toneport_init); | 563 | toneport_init, sizeof(struct usb_line6_toneport)); |
569 | } | 564 | } |
570 | 565 | ||
571 | static struct usb_driver toneport_driver = { | 566 | static struct usb_driver toneport_driver = { |
diff --git a/sound/usb/line6/variax.c b/sound/usb/line6/variax.c index ba6e85eed2ba..9701ffa61365 100644 --- a/sound/usb/line6/variax.c +++ b/sound/usb/line6/variax.c | |||
@@ -296,14 +296,9 @@ static const struct line6_properties variax_properties_table[] = { | |||
296 | static int variax_probe(struct usb_interface *interface, | 296 | static int variax_probe(struct usb_interface *interface, |
297 | const struct usb_device_id *id) | 297 | const struct usb_device_id *id) |
298 | { | 298 | { |
299 | struct usb_line6_variax *variax; | 299 | return line6_probe(interface, id, |
300 | |||
301 | variax = kzalloc(sizeof(*variax), GFP_KERNEL); | ||
302 | if (!variax) | ||
303 | return -ENODEV; | ||
304 | return line6_probe(interface, id, &variax->line6, | ||
305 | &variax_properties_table[id->driver_info], | 300 | &variax_properties_table[id->driver_info], |
306 | variax_init); | 301 | variax_init, sizeof(struct usb_line6_variax)); |
307 | } | 302 | } |
308 | 303 | ||
309 | static struct usb_driver variax_driver = { | 304 | static struct usb_driver variax_driver = { |