aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-01-23 06:24:03 -0500
committerTakashi Iwai <tiwai@suse.de>2015-01-28 01:20:15 -0500
commit644d90850c65c6ac5698e4fadb01682196a25eea (patch)
treee9fc78bd4ea51feff884addd0baa1eb41bfc1f86 /sound/usb
parentf44edd7b2bbeddef602fe84d3b175818024d7fce (diff)
ALSA: line6: Minor refactoring
Split some codes in the lengthy line6_probe(). 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/driver.c94
1 files changed, 49 insertions, 45 deletions
diff --git a/sound/usb/line6/driver.c b/sound/usb/line6/driver.c
index e7f9a99e1949..b783c0788e45 100644
--- a/sound/usb/line6/driver.c
+++ b/sound/usb/line6/driver.c
@@ -448,6 +448,52 @@ static void line6_destruct(struct snd_card *card)
448 usb_put_dev(usbdev); 448 usb_put_dev(usbdev);
449} 449}
450 450
451/* get data from endpoint descriptor (see usb_maxpacket): */
452static void line6_get_interval(struct usb_line6 *line6)
453{
454 struct usb_device *usbdev = line6->usbdev;
455 struct usb_host_endpoint *ep;
456 unsigned pipe = usb_rcvintpipe(usbdev, line6->properties->ep_ctrl_r);
457 unsigned epnum = usb_pipeendpoint(pipe);
458
459 ep = usbdev->ep_in[epnum];
460 if (ep) {
461 line6->interval = ep->desc.bInterval;
462 line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
463 } else {
464 dev_err(line6->ifcdev,
465 "endpoint not available, using fallback values");
466 line6->interval = LINE6_FALLBACK_INTERVAL;
467 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
468 }
469}
470
471static int line6_init_cap_control(struct usb_line6 *line6)
472{
473 int ret;
474
475 /* initialize USB buffers: */
476 line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
477 if (!line6->buffer_listen)
478 return -ENOMEM;
479
480 line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
481 if (!line6->buffer_message)
482 return -ENOMEM;
483
484 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
485 if (!line6->urb_listen)
486 return -ENOMEM;
487
488 ret = line6_start_listen(line6);
489 if (ret < 0) {
490 dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
491 return ret;
492 }
493
494 return 0;
495}
496
451/* 497/*
452 Probe USB device. 498 Probe USB device.
453*/ 499*/
@@ -485,24 +531,7 @@ int line6_probe(struct usb_interface *interface,
485 line6->usbdev = usbdev; 531 line6->usbdev = usbdev;
486 line6->ifcdev = &interface->dev; 532 line6->ifcdev = &interface->dev;
487 533
488 /* get data from endpoint descriptor (see usb_maxpacket): */ 534 line6_get_interval(line6);
489 {
490 struct usb_host_endpoint *ep;
491 unsigned pipe = usb_rcvintpipe(usbdev, properties->ep_ctrl_r);
492 unsigned epnum = usb_pipeendpoint(pipe);
493 ep = usbdev->ep_in[epnum];
494
495 if (ep != NULL) {
496 line6->interval = ep->desc.bInterval;
497 line6->max_packet_size =
498 le16_to_cpu(ep->desc.wMaxPacketSize);
499 } else {
500 line6->interval = LINE6_FALLBACK_INTERVAL;
501 line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
502 dev_err(line6->ifcdev,
503 "endpoint not available, using fallback values");
504 }
505 }
506 535
507 ret = snd_card_new(line6->ifcdev, 536 ret = snd_card_new(line6->ifcdev,
508 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 537 SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
@@ -525,34 +554,9 @@ int line6_probe(struct usb_interface *interface,
525 usb_get_dev(usbdev); 554 usb_get_dev(usbdev);
526 555
527 if (properties->capabilities & LINE6_CAP_CONTROL) { 556 if (properties->capabilities & LINE6_CAP_CONTROL) {
528 /* initialize USB buffers: */ 557 ret = line6_init_cap_control(line6);
529 line6->buffer_listen = 558 if (ret < 0)
530 kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
531 if (line6->buffer_listen == NULL) {
532 ret = -ENOMEM;
533 goto err_destruct;
534 }
535
536 line6->buffer_message =
537 kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
538 if (line6->buffer_message == NULL) {
539 ret = -ENOMEM;
540 goto err_destruct; 559 goto err_destruct;
541 }
542
543 line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
544
545 if (line6->urb_listen == NULL) {
546 ret = -ENOMEM;
547 goto err_destruct;
548 }
549
550 ret = line6_start_listen(line6);
551 if (ret < 0) {
552 dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
553 __func__);
554 goto err_destruct;
555 }
556 } 560 }
557 561
558 /* initialize device data based on device: */ 562 /* initialize device data based on device: */