Skip to contentSkip to conversation

usb: gadget: f_uac2: prevent invalid bInterval auto-selection

PATCH In review Kyle Farrell 4 participants 5 messages Oct 28 – Nov 17 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: f_uac2: prevent invalid bInterval auto-selection

When p_hs_bint or c_hs_bint is 0, the driver selects the largest bInterval from 4 down to 1 for which the required bandwidth fits the maximum packet size. The original implementation intends to keep bInterval at 1 when required bandwidth exceeds the single-packet maximum, but the search loop instead decrements bInterval to 0 in that case.

A bInterval of 0 is invalid for an isochronous endpoint. A Linux host reports it and substitutes a default:

usb 3-8: ... endpoint 0x1 has an invalid bInterval 0, changing to 7

Stop the search at bInterval=1. Maintain existing clamping of wMaxPacketSize and warning about possible data loss when the required bandwidth cannot be accommodated.

Fixes 355a05dc8367 ("usb: gadget: f_uac2: Optionally determine bInterval for HS and SS")
---
 drivers/usb/gadget/function/f_uac2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/usb/gadget/function/f_uac2.c +3 -3
index d8cf710085a0..9bd59ea5f7fb 100644
@@ -728,11 +728,11 @@ static int set_ep_max_packet_size_bint(struct device *dev, const struct f_uac2_o
 			bint = opts_bint;
 			max_size_bw = get_max_bw_for_bint(uac2_opts, bint, 8000, is_playback);
 		} else {
-			/* checking bInterval from 4 to 1 whether the required bandwidth fits */
-			for (bint = 4; bint > 0; --bint) {
+			/* select the largest bInterval that fits, or 1 if none fit */
+			for (bint = 4; ; --bint) {
 				max_size_bw = get_max_bw_for_bint(
 					uac2_opts, bint, 8000, is_playback);
-				if (max_size_bw <= max_size_ep)
+				if (max_size_bw <= max_size_ep || bint == 1)
 					break;
 			}
 		}

base-commit: bdf12cde30830d46a8ef1ba93986356f1164b4f1

Signature · 1 line
2.34.1
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

When p_hs_bint or c_hs_bint is 0, the driver selects the largest bInterval from 4 down to 1 for which the required bandwidth fits the maximum packet size. The original implementation intends to keep bInterval at 1 when required bandwidth exceeds the single-packet maximum, but the search loop instead decrements bInterval to 0 in that case.

A bInterval of 0 is invalid for an isochronous endpoint. A Linux host reports it and substitutes a default:

Quoted 8 lines

usb 3-8: ... endpoint 0x1 has an invalid bInterval 0, changing to 7

Stop the search at bInterval=1. Maintain existing clamping of wMaxPacketSize and warning about possible data loss when the required bandwidth cannot be accommodated.

Fixes 355a05dc8367 ("usb: gadget: f_uac2: Optionally determine bInterval for HS and SS")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Kyle Farrell
Quoted 9 lines

When p_hs_bint or c_hs_bint is 0, the driver selects the largest bInterval from 4 down to 1 for which the required bandwidth fits the maximum packet size. The original implementation intends to keep bInterval at 1 when required bandwidth exceeds the single-packet maximum, but the search loop instead decrements bInterval to 0 in that case.

A bInterval of 0 is invalid for an isochronous endpoint. A Linux host reports it and substitutes a default:

Quoted 7 lines

usb 3-8: ... endpoint 0x1 has an invalid bInterval 0, changing to 7

Stop the search at bInterval=1. Maintain existing clamping of wMaxPacketSize and warning about possible data loss when the required bandwidth cannot be accommodated.

Fixes 355a05dc8367 ("usb: gadget: f_uac2: Optionally determine bInterval for HS and SS")

The change looks good to me but you're missing Cc: [email protected]

Signature · 1 line
Neill Kapron <[email protected]>
#3 lore raw
Quoted 15 lines · Neill Kapron
Quoted 15 lines

When p_hs_bint or c_hs_bint is 0, the driver selects the largest bInterval from 4 down to 1 for which the required bandwidth fits the maximum packet size. The original implementation intends to keep bInterval at 1 when required bandwidth exceeds the single-packet maximum, but the search loop instead decrements bInterval to 0 in that case.

A bInterval of 0 is invalid for an isochronous endpoint. A Linux host reports it and substitutes a default:

usb 3-8: ... endpoint 0x1 has an invalid bInterval 0, changing to 7

Stop the search at bInterval=1. Maintain existing clamping of wMaxPacketSize and warning about possible data loss when the required bandwidth cannot be accommodated.

Quoted 5 lines
Quoted 1 line
Fixes 355a05dc8367 ("usb: gadget: f_uac2: Optionally determine bInterval for HS and SS")

The change looks good to me but you're missing Cc: [email protected]

Thanks Neill. I'll make sure to include the stable Cc on applicable fixes going forward. Could I ask that you add the trailer when applying the patch?

Thanks,
Kyle Farrell

maintainer
#4 lore raw
Quoted 23 lines · On Mon, Nov 16, 2026 at 12:58:57PM -0800, [email protected] wrote:
Quoted 22 lines · Neill Kapron
Quoted 10 lines

When p_hs_bint or c_hs_bint is 0, the driver selects the largest bInterval from 4 down to 1 for which the required bandwidth fits the maximum packet size. The original implementation intends to keep bInterval at 1 when required bandwidth exceeds the single-packet maximum,
but the search loop instead decrements bInterval to 0 in that case.

A bInterval of 0 is invalid for an isochronous endpoint. A Linux host reports it and substitutes a default:

Quoted 8 lines

usb 3-8: ... endpoint 0x1 has an invalid bInterval 0, changing to 7

Stop the search at bInterval=1. Maintain existing clamping of wMaxPacketSize and warning about possible data loss when the required bandwidth cannot be accommodated.

Fixes 355a05dc8367 ("usb: gadget: f_uac2: Optionally determine

bInterval for HS and SS")

The change looks good to me but you're missing Cc:
[email protected]

Quoted 7 lines
Quoted 1 line

Thanks Neill. I'll make sure to include the stable Cc on applicable fixes going forward.
Could I ask that you add the trailer when applying the patch?

I can do so, thanks.