* [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame
@ 2026-10-26 23:10 Kyle Farrell
2026-10-26 23:15 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Kyle Farrell @ 2026-10-26 23:10 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Neill Kapron, linux-usb, Kyle Farrell
u_audio_iso_complete() clamps the base packet size to ep->maxpacket
and accumulates fractional-frame residue in p_residue_mil. Once a
whole frame has accumulated, it is appended to the packet without
checking whether it fits within ep->maxpacket.
Only append the extra frame if it fits. Consume the accumulated
residue whether or not the frame is sent, preventing it from growing
when the additional frame cannot fit. When the frame fits, behavior
is unchanged. Otherwise, the stream cannot sustain the requested
sample rate.
For example, with 27 channels of 32-bit samples at 19200 Hz on a
high-speed link with p_hs_bint=3, the required packet size of 1080
bytes is capped at 1024. The base packet is 972 bytes, but appending
a residue frame increases it to 1080 bytes, exceeding the allocated
request buffer by 56 bytes.
Fixes: 9bb87f168931 ("usb: gadget: f_uac2: send reasonably sized packets")
Link: https://lore.kernel.org/linux-usb/sashiko-outbox-174688@kernel.org/
Signed-off-by: Kyle Farrell <kaf@nwlink.com>
---
drivers/usb/gadget/function/u_audio.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index f0ee83abcebc..f73d1085c1d1 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -230,9 +230,13 @@ static void u_audio_iso_complete(struct usb_ep *ep, struct usb_request *req)
do_div(div_result, uac->p_interval);
do_div(div_result, 1000000);
if ((unsigned int) div_result >= uac->p_framesize) {
- req->length += uac->p_framesize;
+ /* req->length is bounded by ep->maxpacket above. */
+ if (uac->p_framesize <= ep->maxpacket - req->length) {
+ req->length += uac->p_framesize;
+ pr_debug("increased req length to %d\n", req->length);
+ }
+
uac->p_residue_mil -= uac->p_framesize * p_interval_mil;
- pr_debug("increased req length to %d\n", req->length);
}
pr_debug("remains uac->p_residue_mil %llu\n", uac->p_residue_mil);
base-commit: bdf12cde30830d46a8ef1ba93986356f1164b4f1
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame
2026-10-26 23:10 [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame Kyle Farrell
@ 2026-10-26 23:15 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-26 23:15 UTC (permalink / raw)
To: Kyle Farrell; +Cc: linux-usb
> u_audio_iso_complete() clamps the base packet size to ep->maxpacket
> and accumulates fractional-frame residue in p_residue_mil. Once a
> whole frame has accumulated, it is appended to the packet without
> checking whether it fits within ep->maxpacket.
>
> Only append the extra frame if it fits. Consume the accumulated
> residue whether or not the frame is sent, preventing it from growing
> when the additional frame cannot fit. When the frame fits, behavior
> is unchanged. Otherwise, the stream cannot sustain the requested
> sample rate.
>
> For example, with 27 channels of 32-bit samples at 19200 Hz on a
> high-speed link with p_hs_bint=3, the required packet size of 1080
> bytes is capped at 1024. The base packet is 972 bytes, but appending
> a residue frame increases it to 1080 bytes, exceeding the allocated
> request buffer by 56 bytes.
>
> Fixes: 9bb87f168931 ("usb: gadget: f_uac2: send reasonably sized packets")
> Link: https://lore.kernel.org/linux-usb/sashiko-outbox-174688@kernel.org/
> Signed-off-by: Kyle Farrell <kaf@nwlink.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261026231026.721536-1-kaf@nwlink.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-26 23:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-26 23:10 [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame Kyle Farrell
2026-10-26 23:15 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox