Index | Thread | Search

From:
"Jonathan Armani" <jonathan@armani.tech>
Subject:
Re: uaudio(4): dynamic feature unit control size for UAC2
To:
"Andrew Kloet" <andrew@kloet.net>, "Alexandre Ratchov" <alex@caoua.org>
Cc:
tech@openbsd.org
Date:
Sun, 15 Nov 2026 16:24:52 +0100

Download raw body.

Thread
Hello Andrew, Alex,

Perfect occupation for a rainy day :)

From what I read in your USB dump, the feature units are 18 bytes
long, i.e. master + 2 per-channel bitmaps, but their sources have
8 and 4 channels so we run out of descriptor in the per-channel
loop.

If I understand it correctly, your diff works by accident : on UAC2
it reads the low byte of bmaControls(0) as bControlSize, which is 0
here, so size = 0 and uaudio_getnum() never fails.

Could you try the diff below instead ? It stops the loop when the
descriptor is exhausted, which also covers the existing "no
per-channel descriptors" special case.

Also, could you send a raw dump of the descriptor ?  I'd expect
1 byte left at the failure point, not 28.

--- a/sys/dev/usb/uaudio.c
+++ b/sys/dev/usb/uaudio.c
@@ -1494,13 +1494,13 @@ uaudio_process_unit(struct uaudio_softc
 			ctl >>= 2;
 		}
 
-		/*
-		 * certain devices provide no per-channel control descriptors
-		 */
-		if (p.wptr - p.rptr == 1)
-			break;
-
 		for (j = 0; j < u->nch; j++) {
+			/*
+			 * certain devices provide fewer per-channel
+			 * control descriptors than channels (or none)
+			 */
+			if (p.wptr - p.rptr < size)
+				break;
 			if (!uaudio_getnum(&p, size, &ctl))
 				return 0;
 			ctl = uaudio_feature_fixup(sc, ctl);

On Sat, Nov 14, 2026, at 23:30, Andrew Kloet wrote:
> On Thu Nov 12, 2026 at 3:36 AM EST, Alexandre Ratchov wrote:
>> On Tue, Nov 10, 2026 at 06:37:33PM -0500, Andrew Kloet wrote:
>>> Hello tech@
>>> 
>>> While attaching a 'Teenage Engineering EP-136' audio interface...
>>> uaudio(4) uaudio_process_unit() fails feature unit parsing.
>>> 
>>> Under UAUDIO_AC_FEATURE, the driver hardcodes size = 4 for UAUDIO_V2.
>>> However, both UAC1/2 specs read bControlSize from the descriptor.
>>> Hardcoding size = 4 causes uaudio_getnum() to overrun on devices whose
>>> feature units specify a different control size.
>>> 
>>> Fetching bControlSize dynamically for both V1 and V2 resolves the issue.
>>> 
>>
>> AFAIU, the UAC 2.0 FEATURE_UNIT descriptor has not bControlSize
>> field. All the bmaControls bitmaps are of fixed size 4.
>>
>> What causes the failure? Is the descriptor too small?
>
> Hm, you're right. I read the spec wrong, it should be fixed at 4.
> Though the patch still does resolve the issue for me.
>
> Here is plugging the device in with UAUDIO_DEBUG:
>
> uaudio0 at uhub0 port 4 configuration 1 interface 1 "teenage 
> engineering EP-136" rev 2.00/1.01 addr 7
> uaudio_process_ac: ifnum = 0, 328 bytes to process
> uaudio_process_header: version 0x200
> 16: clock source, attr = 0x1, ctl = 0x7
> 01: in, nch = 8, term = 0x603, assoc = 0
> 02: feature id = 1, nch = 8, size = 4
> uaudio_getnum: 4: too small
> uaudio1 at uhub0 port 4 configuration 1 interface 2 "teenage 
> engineering EP-136" rev 2.00/1.01 addr 7
> uaudio_process_ac: ifnum = 0, 328 bytes to process
> uaudio_process_header: version 0x200
> 16: clock source, attr = 0x1, ctl = 0x7
> 01: in, nch = 8, term = 0x603, assoc = 0
> 02: feature id = 1, nch = 8, size = 4
> uaudio_getnum: 4: too small
> umidi0 at uhub0 port 4 configuration 1 interface 4 "teenage engineering 
> EP-136" rev 2.00/1.01 addr 7
> umidi0: (genuine USB-MIDI)
> umidi0: out=1, in=1
> midi0 at umidi0: <USB MIDI I/F>
> ugen3 at uhub0 port 4 configuration 1 "teenage engineering EP-136" rev 
> 2.00/1.01 addr 7
>
> And lsusb -v
>
> Bus 000 Device 007: ID 2367:9420
> Device Descriptor:
>   bLength                18
>   bDescriptorType         1
>   bcdUSB               2.00
>   bDeviceClass            0 (Defined at Interface level)
>   bDeviceSubClass         0
>   bDeviceProtocol         1
>   bMaxPacketSize0        64
>   idVendor           0x2367
>   idProduct          0x9420
>   bcdDevice            1.01
>   iManufacturer           1 teenage engineering
>   iProduct                2 EP-136
>   iSerial                 3 8300012912252000xx
>   bNumConfigurations      1
>   Configuration Descriptor:
>     bLength                 9
>     bDescriptorType         2
>     wTotalLength          354
>     bNumInterfaces          5
>     bConfigurationValue     1
>     iConfiguration          0
>     bmAttributes         0xc0
>       Self Powered
>     MaxPower              500mA
>     Interface Association:
>       bLength                 8
>       bDescriptorType        11
>       bFirstInterface         0
>       bInterfaceCount         3
>       bFunctionClass          1 Audio
>       bFunctionSubClass       0
>       bFunctionProtocol      32
>       iFunction               0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        0
>       bAlternateSetting       0
>       bNumEndpoints           0
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      1 Control Device
>       bInterfaceProtocol     32
>       iInterface              0
>       AudioControl Interface Descriptor:
>         bLength                 9
>         bDescriptorType        36
>         bDescriptorSubtype      1 (HEADER)
>         bcdADC               2.00
>         bCategory              10
>         wTotalLength          111
>         bmControl            0x00
>       AudioControl Interface Descriptor:
>         bLength                 8
>         bDescriptorType        36
>         bDescriptorSubtype     10 (CLOCK_SOURCE)
>         bClockID               16
>         bmAttributes         0x01 Internal fixed Clock
>         bmControls           0x07
>           Clock Frequency Control (read/write)
>           Clock Validity Control (read-only)
>         bAssocTerminal          0
>         iClockSource            0
>       AudioControl Interface Descriptor:
>         bLength                17
>         bDescriptorType        36
>         bDescriptorSubtype      2 (INPUT_TERMINAL)
>         bTerminalID             1
>         wTerminalType      0x0603 Line Connector
>         bAssocTerminal          0
>         bCSourceID             16
>         bNrChannels             8
>         bmChannelConfig   0x00000000
>         bmControls    0x0000
>         iChannelNames           4 MAIN L
>         iTerminal               0
>       AudioControl Interface Descriptor:
>         bLength                18
>         bDescriptorType        36
>         bDescriptorSubtype      6 (FEATURE_UNIT)
>         bUnitID                 2
>         bSourceID               1
>         bmaControls( 0)      0x00000000
>         bmaControls( 1)      0x00000000
>         bmaControls( 2)      0x00000000
>         iFeature                0
>       AudioControl Interface Descriptor:
>         bLength                12
>         bDescriptorType        36
>         bDescriptorSubtype      3 (OUTPUT_TERMINAL)
>         bTerminalID             3
>         wTerminalType      0x0101 USB Streaming
>         bAssocTerminal          0
>         bSourceID               2
>         bCSourceID             16
>         bmControls         0x0000
>         iTerminal               0
>       AudioControl Interface Descriptor:
>         bLength                17
>         bDescriptorType        36
>         bDescriptorSubtype      2 (INPUT_TERMINAL)
>         bTerminalID             4
>         wTerminalType      0x0101 USB Streaming
>         bAssocTerminal          0
>         bCSourceID             16
>         bNrChannels             4
>         bmChannelConfig   0x00000000
>         bmControls    0x0000
>         iChannelNames          12 1 L
>         iTerminal               0
>       AudioControl Interface Descriptor:
>         bLength                18
>         bDescriptorType        36
>         bDescriptorSubtype      6 (FEATURE_UNIT)
>         bUnitID                 5
>         bSourceID               4
>         bmaControls( 0)      0x00000000
>         bmaControls( 1)      0x00000000
>         bmaControls( 2)      0x00000000
>         iFeature                0
>       AudioControl Interface Descriptor:
>         bLength                12
>         bDescriptorType        36
>         bDescriptorSubtype      3 (OUTPUT_TERMINAL)
>         bTerminalID             6
>         wTerminalType      0x0603 Line Connector
>         bAssocTerminal          0
>         bSourceID               5
>         bCSourceID             16
>         bmControls         0x0000
>         iTerminal               0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        1
>       bAlternateSetting       0
>       bNumEndpoints           0
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      2 Streaming
>       bInterfaceProtocol     32
>       iInterface              0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        1
>       bAlternateSetting       1
>       bNumEndpoints           1
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      2 Streaming
>       bInterfaceProtocol     32
>       iInterface              0
>       AudioStreaming Interface Descriptor:
>         bLength                16
>         bDescriptorType        36
>         bDescriptorSubtype      1 (AS_GENERAL)
>         bTerminalLink           3
>         bmControls           0x00
>         bFormatType             1
>         bmFormats         0x00000001
>           PCM
>         bNrChannels             8
>         bmChannelConfig   0x00000000
>         iChannelNames           4 MAIN L
>       AudioStreaming Interface Descriptor:
>         bLength                 6
>         bDescriptorType        36
>         bDescriptorSubtype      2 (FORMAT_TYPE)
>         bFormatType             1 (FORMAT_TYPE_I)
>         bSubslotSize            4
>         bBitResolution         32
>       Endpoint Descriptor:
>         bLength                 7
>         bDescriptorType         5
>         bEndpointAddress     0x82  EP 2 IN
>         bmAttributes           37
>           Transfer Type            Isochronous
>           Synch Type               Asynchronous
>           Usage Type               Implicit feedback Data
>         wMaxPacketSize     0x00e0  1x 224 bytes
>         bInterval               1
>         AudioControl Endpoint Descriptor:
>           bLength                 8
>           bDescriptorType        37
>           bDescriptorSubtype      1 (EP_GENERAL)
>           bmAttributes         0x00
>           bmControls           0x00
>           bLockDelayUnits         0 Undefined
>           wLockDelay              0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        2
>       bAlternateSetting       0
>       bNumEndpoints           0
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      2 Streaming
>       bInterfaceProtocol     32
>       iInterface              0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        2
>       bAlternateSetting       1
>       bNumEndpoints           2
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      2 Streaming
>       bInterfaceProtocol     32
>       iInterface              0
>       AudioStreaming Interface Descriptor:
>         bLength                16
>         bDescriptorType        36
>         bDescriptorSubtype      1 (AS_GENERAL)
>         bTerminalLink           4
>         bmControls           0x00
>         bFormatType             1
>         bmFormats         0x00000001
>           PCM
>         bNrChannels             4
>         bmChannelConfig   0x00000000
>         iChannelNames          12 1 L
>       AudioStreaming Interface Descriptor:
>         bLength                 6
>         bDescriptorType        36
>         bDescriptorSubtype      2 (FORMAT_TYPE)
>         bFormatType             1 (FORMAT_TYPE_I)
>         bSubslotSize            4
>         bBitResolution         32
>       Endpoint Descriptor:
>         bLength                 7
>         bDescriptorType         5
>         bEndpointAddress     0x02  EP 2 OUT
>         bmAttributes            5
>           Transfer Type            Isochronous
>           Synch Type               Asynchronous
>           Usage Type               Data
>         wMaxPacketSize     0x0070  1x 112 bytes
>         bInterval               1
>         AudioControl Endpoint Descriptor:
>           bLength                 8
>           bDescriptorType        37
>           bDescriptorSubtype      1 (EP_GENERAL)
>           bmAttributes         0x00
>           bmControls           0x00
>           bLockDelayUnits         0 Undefined
>           wLockDelay              0
>       Endpoint Descriptor:
>         bLength                 7
>         bDescriptorType         5
>         bEndpointAddress     0x81  EP 1 IN
>         bmAttributes           17
>           Transfer Type            Isochronous
>           Synch Type               None
>           Usage Type               Feedback
>         wMaxPacketSize     0x0004  1x 4 bytes
>         bInterval               4
>     Interface Association:
>       bLength                 8
>       bDescriptorType        11
>       bFirstInterface         3
>       bInterfaceCount         2
>       bFunctionClass          1 Audio
>       bFunctionSubClass       0
>       bFunctionProtocol       0
>       iFunction               0
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        3
>       bAlternateSetting       0
>       bNumEndpoints           0
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      1 Control Device
>       bInterfaceProtocol      0
>       iInterface              0
>       AudioControl Interface Descriptor:
>         bLength                 9
>         bDescriptorType        36
>         bDescriptorSubtype      1 (HEADER)
>         bcdADC               1.00
>         wTotalLength            9
>         bInCollection           1
>         baInterfaceNr( 0)       4
>     Interface Descriptor:
>       bLength                 9
>       bDescriptorType         4
>       bInterfaceNumber        4
>       bAlternateSetting       0
>       bNumEndpoints           2
>       bInterfaceClass         1 Audio
>       bInterfaceSubClass      3 MIDI Streaming
>       bInterfaceProtocol      0
>       iInterface              0
>       MIDIStreaming Interface Descriptor:
>         bLength                 7
>         bDescriptorType        36
>         bDescriptorSubtype      1 (HEADER)
>         bcdADC               1.00
>         wTotalLength           65
>       MIDIStreaming Interface Descriptor:
>         bLength                 6
>         bDescriptorType        36
>         bDescriptorSubtype      2 (MIDI_IN_JACK)
>         bJackType               1 Embedded
>         bJackID                 1
>         iJack                   0
>       MIDIStreaming Interface Descriptor:
>         bLength                 6
>         bDescriptorType        36
>         bDescriptorSubtype      2 (MIDI_IN_JACK)
>         bJackType               2 External
>         bJackID                 2
>         iJack                   0
>       MIDIStreaming Interface Descriptor:
>         bLength                 9
>         bDescriptorType        36
>         bDescriptorSubtype      3 (MIDI_OUT_JACK)
>         bJackType               1 Embedded
>         bJackID                 3
>         bNrInputPins            1
>         baSourceID( 0)          2
>         BaSourcePin( 0)         1
>         iJack                   0
>       MIDIStreaming Interface Descriptor:
>         bLength                 9
>         bDescriptorType        36
>         bDescriptorSubtype      3 (MIDI_OUT_JACK)
>         bJackType               2 External
>         bJackID                 4
>         bNrInputPins            1
>         baSourceID( 0)          1
>         BaSourcePin( 0)         1
>         iJack                   0
>       Endpoint Descriptor:
>         bLength                 9
>         bDescriptorType         5
>         bEndpointAddress     0x03  EP 3 OUT
>         bmAttributes            2
>           Transfer Type            Bulk
>           Synch Type               None
>           Usage Type               Data
>         wMaxPacketSize     0x0200  1x 512 bytes
>         bInterval               0
>         bRefresh                0
>         bSynchAddress           0
>         MIDIStreaming Endpoint Descriptor:
>           bLength                 5
>           bDescriptorType        37
>           bDescriptorSubtype      1 (GENERAL)
>           bNumEmbMIDIJack         1
>           baAssocJackID( 0)       1
>       Endpoint Descriptor:
>         bLength                 9
>         bDescriptorType         5
>         bEndpointAddress     0x83  EP 3 IN
>         bmAttributes            2
>           Transfer Type            Bulk
>           Synch Type               None
>           Usage Type               Data
>         wMaxPacketSize     0x0200  1x 512 bytes
>         bInterval               7
>         bRefresh                0
>         bSynchAddress           0
>         MIDIStreaming Endpoint Descriptor:
>           bLength                 5
>           bDescriptorType        37
>           bDescriptorSubtype      1 (GENERAL)
>           bNumEmbMIDIJack         1
>           baAssocJackID( 0)       3
> Device Status:     0x0001
>   Self Powered
>
> I made uaudio_getnum print `p->wptr - p->rptr` when < `size`,
> for my device it prints 28.
>
> Please let me know if there are other tests you'd like to see.
>
> -- 
> Andrew
>
> Attachments:
> * signature.asc