mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
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>
This commit is contained in:
parent
f44edd7b2b
commit
644d90850c
1 changed files with 49 additions and 45 deletions
|
@ -448,6 +448,52 @@ static void line6_destruct(struct snd_card *card)
|
||||||
usb_put_dev(usbdev);
|
usb_put_dev(usbdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get data from endpoint descriptor (see usb_maxpacket): */
|
||||||
|
static void line6_get_interval(struct usb_line6 *line6)
|
||||||
|
{
|
||||||
|
struct usb_device *usbdev = line6->usbdev;
|
||||||
|
struct usb_host_endpoint *ep;
|
||||||
|
unsigned pipe = usb_rcvintpipe(usbdev, line6->properties->ep_ctrl_r);
|
||||||
|
unsigned epnum = usb_pipeendpoint(pipe);
|
||||||
|
|
||||||
|
ep = usbdev->ep_in[epnum];
|
||||||
|
if (ep) {
|
||||||
|
line6->interval = ep->desc.bInterval;
|
||||||
|
line6->max_packet_size = le16_to_cpu(ep->desc.wMaxPacketSize);
|
||||||
|
} else {
|
||||||
|
dev_err(line6->ifcdev,
|
||||||
|
"endpoint not available, using fallback values");
|
||||||
|
line6->interval = LINE6_FALLBACK_INTERVAL;
|
||||||
|
line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int line6_init_cap_control(struct usb_line6 *line6)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* initialize USB buffers: */
|
||||||
|
line6->buffer_listen = kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
|
||||||
|
if (!line6->buffer_listen)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
line6->buffer_message = kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
|
||||||
|
if (!line6->buffer_message)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
|
||||||
|
if (!line6->urb_listen)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
|
ret = line6_start_listen(line6);
|
||||||
|
if (ret < 0) {
|
||||||
|
dev_err(line6->ifcdev, "cannot start listening: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Probe USB device.
|
Probe USB device.
|
||||||
*/
|
*/
|
||||||
|
@ -485,24 +531,7 @@ int line6_probe(struct usb_interface *interface,
|
||||||
line6->usbdev = usbdev;
|
line6->usbdev = usbdev;
|
||||||
line6->ifcdev = &interface->dev;
|
line6->ifcdev = &interface->dev;
|
||||||
|
|
||||||
/* get data from endpoint descriptor (see usb_maxpacket): */
|
line6_get_interval(line6);
|
||||||
{
|
|
||||||
struct usb_host_endpoint *ep;
|
|
||||||
unsigned pipe = usb_rcvintpipe(usbdev, properties->ep_ctrl_r);
|
|
||||||
unsigned epnum = usb_pipeendpoint(pipe);
|
|
||||||
ep = usbdev->ep_in[epnum];
|
|
||||||
|
|
||||||
if (ep != NULL) {
|
|
||||||
line6->interval = ep->desc.bInterval;
|
|
||||||
line6->max_packet_size =
|
|
||||||
le16_to_cpu(ep->desc.wMaxPacketSize);
|
|
||||||
} else {
|
|
||||||
line6->interval = LINE6_FALLBACK_INTERVAL;
|
|
||||||
line6->max_packet_size = LINE6_FALLBACK_MAXPACKETSIZE;
|
|
||||||
dev_err(line6->ifcdev,
|
|
||||||
"endpoint not available, using fallback values");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = snd_card_new(line6->ifcdev,
|
ret = snd_card_new(line6->ifcdev,
|
||||||
SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
|
SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
|
||||||
|
@ -525,34 +554,9 @@ int line6_probe(struct usb_interface *interface,
|
||||||
usb_get_dev(usbdev);
|
usb_get_dev(usbdev);
|
||||||
|
|
||||||
if (properties->capabilities & LINE6_CAP_CONTROL) {
|
if (properties->capabilities & LINE6_CAP_CONTROL) {
|
||||||
/* initialize USB buffers: */
|
ret = line6_init_cap_control(line6);
|
||||||
line6->buffer_listen =
|
if (ret < 0)
|
||||||
kmalloc(LINE6_BUFSIZE_LISTEN, GFP_KERNEL);
|
|
||||||
if (line6->buffer_listen == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto err_destruct;
|
goto err_destruct;
|
||||||
}
|
|
||||||
|
|
||||||
line6->buffer_message =
|
|
||||||
kmalloc(LINE6_MESSAGE_MAXLEN, GFP_KERNEL);
|
|
||||||
if (line6->buffer_message == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto err_destruct;
|
|
||||||
}
|
|
||||||
|
|
||||||
line6->urb_listen = usb_alloc_urb(0, GFP_KERNEL);
|
|
||||||
|
|
||||||
if (line6->urb_listen == NULL) {
|
|
||||||
ret = -ENOMEM;
|
|
||||||
goto err_destruct;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = line6_start_listen(line6);
|
|
||||||
if (ret < 0) {
|
|
||||||
dev_err(&interface->dev, "%s: usb_submit_urb failed\n",
|
|
||||||
__func__);
|
|
||||||
goto err_destruct;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize device data based on device: */
|
/* initialize device data based on device: */
|
||||||
|
|
Loading…
Add table
Reference in a new issue