Skip to content

Commit 5c6cd70

Browse files
ansteintiwai
authored andcommitted
ALSA: usb-audio: Fix case when USB MIDI interface has more than one extra endpoint descriptor
The Miditech MIDIFACE 16x16 (USB ID 1290:1749) has more than one extra endpoint descriptor. The first extra descriptor is: 0x06 0x30 0x00 0x00 0x00 0x00 As the code in snd_usbmidi_get_ms_info() looks only at the first extra descriptor to find USB_DT_CS_ENDPOINT the device as such is recognized but there is neither input nor output configured. The patch iterates through the extra descriptors to find the proper one. With this patch the device is correctly configured. Signed-off-by: Andreas Steinmetz <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent b6f69c7 commit 5c6cd70

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

sound/usb/midi.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,6 +1826,28 @@ static int snd_usbmidi_create_endpoints(struct snd_usb_midi *umidi,
18261826
return 0;
18271827
}
18281828

1829+
static struct usb_ms_endpoint_descriptor *find_usb_ms_endpoint_descriptor(
1830+
struct usb_host_endpoint *hostep)
1831+
{
1832+
unsigned char *extra = hostep->extra;
1833+
int extralen = hostep->extralen;
1834+
1835+
while (extralen > 3) {
1836+
struct usb_ms_endpoint_descriptor *ms_ep =
1837+
(struct usb_ms_endpoint_descriptor *)extra;
1838+
1839+
if (ms_ep->bLength > 3 &&
1840+
ms_ep->bDescriptorType == USB_DT_CS_ENDPOINT &&
1841+
ms_ep->bDescriptorSubtype == UAC_MS_GENERAL)
1842+
return ms_ep;
1843+
if (!extra[0])
1844+
break;
1845+
extralen -= extra[0];
1846+
extra += extra[0];
1847+
}
1848+
return NULL;
1849+
}
1850+
18291851
/*
18301852
* Returns MIDIStreaming device capabilities.
18311853
*/
@@ -1863,11 +1885,8 @@ static int snd_usbmidi_get_ms_info(struct snd_usb_midi *umidi,
18631885
ep = get_ep_desc(hostep);
18641886
if (!usb_endpoint_xfer_bulk(ep) && !usb_endpoint_xfer_int(ep))
18651887
continue;
1866-
ms_ep = (struct usb_ms_endpoint_descriptor *)hostep->extra;
1867-
if (hostep->extralen < 4 ||
1868-
ms_ep->bLength < 4 ||
1869-
ms_ep->bDescriptorType != USB_DT_CS_ENDPOINT ||
1870-
ms_ep->bDescriptorSubtype != UAC_MS_GENERAL)
1888+
ms_ep = find_usb_ms_endpoint_descriptor(hostep);
1889+
if (!ms_ep)
18711890
continue;
18721891
if (usb_endpoint_dir_out(ep)) {
18731892
if (endpoints[epidx].out_ep) {

0 commit comments

Comments
 (0)