From: Kyle Farrell <kaf@nwlink.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Neill Kapron <nkapron@google.com>,
linux-usb@vger.kernel.org, Kyle Farrell <kaf@nwlink.com>
Subject: [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame
Date: Mon, 26 Oct 2026 16:10:26 -0700 [thread overview]
Message-ID: <20261026231026.721536-1-kaf@nwlink.com> (raw)
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
next reply other threads:[~2026-10-26 23:10 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-26 23:10 Kyle Farrell [this message]
2026-10-26 23:15 ` [PATCH] usb: gadget: u_audio: don't exceed maxpacket when adding a residue frame sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261026231026.721536-1-kaf@nwlink.com \
--to=kaf@nwlink.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox