From: Alan Stern <stern@rowland.harvard.edu>
To: Sebastian Urban <surban@surban.net>
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] usb: gadget: dummy_hcd: fix data corruption with queued requests
Date: Sun, 15 Mar 2026 10:44:31 -0400 [thread overview]
Message-ID: <9f2c403b-5955-4e6b-a356-330cebead7ed@rowland.harvard.edu> (raw)
In-Reply-To: <20260315090307.304644-1-surban@surban.net>
On Sun, Mar 15, 2026 at 10:03:07AM +0100, Sebastian Urban wrote:
> The transfer() function in dummy_hcd iterates over all queued gadget
> requests for a given endpoint via list_for_each_entry(). When the
> per-frame bandwidth budget is exhausted mid-request, leaving a
> partially-transferred gadget request, the loop continues to the next
> queued request instead of stopping.
Why do you say this? Did you not see the code (at line 1445
approximately):
if (unlikely(len == 0))
is_short = 1;
else {
/* not enough bandwidth left? */
if (limit < ep->ep.maxpacket && limit < len)
break;
It does break out of the loop when there is not enough space remaining
in the bandwidth budget for another transaction. But it does so at the
start of the iteration following the last allowed transfer, rather than
at the end of last transfer's iteration (as your patch does).
Furthermore, this test can't be removed, as there might not be enough
space remaining for even a single transaction.
> This breaks data ordering in the
> URB transfer buffer.
>
> Two consequences:
>
> 1. Data corruption: bytes from subsequent requests are written into
> the URB buffer ahead of the remaining bytes from the incomplete
> request. On the next timer tick the incomplete request resumes,
> appending its remaining data after the out-of-order bytes.
>
> 2. Premature URB completion: if the next request is a ZLP or shorter
> than the remaining host buffer, it triggers the is_short path and
> completes the URB before all data has been transferred.
>
> Fix this by breaking out of the loop when the current request has
> remaining data (req->req.actual < req->req.length). The request
> resumes on the next timer tick, preserving data ordering.
As far as I can tell, this change is not necessary. While it would
avoid executing a few extra statements in the unlikely case where a
request spans multiple URBs, in most situations it just adds a redundant
test.
Alan Stern
> Signed-off-by: Sebastian Urban <surban@surban.net>
> ---
> drivers/usb/gadget/udc/dummy_hcd.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
> index 1cefca660..0eead4a85 100644
> --- a/drivers/usb/gadget/udc/dummy_hcd.c
> +++ b/drivers/usb/gadget/udc/dummy_hcd.c
> @@ -1534,6 +1534,12 @@ static int transfer(struct dummy_hcd *dum_hcd, struct urb *urb,
> /* rescan to continue with any other queued i/o */
> if (rescan)
> goto top;
> +
> + /* request not fully transferred; stop iterating to
> + * preserve data ordering across queued requests.
> + */
> + if (req->req.actual < req->req.length)
> + break;
> }
> return sent;
> }
> --
> 2.53.0
>
>
next prev parent reply other threads:[~2026-03-15 14:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-15 9:03 Sebastian Urban
2026-03-15 14:44 ` Alan Stern [this message]
2026-03-15 15:06 ` Sebastian Urban
2026-03-15 15:21 ` Alan Stern
2026-03-15 15:28 ` Alan Stern
2026-03-15 15:55 ` Sebastian Urban
2026-03-15 18:23 ` Alan Stern
2026-03-15 15:10 ` [PATCH v2] usb: gadget: dummy_hcd: fix premature URB completion when ZLP follows partial transfer Sebastian Urban
2026-03-15 18:24 ` Alan Stern
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=9f2c403b-5955-4e6b-a356-330cebead7ed@rowland.harvard.edu \
--to=stern@rowland.harvard.edu \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=surban@surban.net \
/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
all inboxes | Powered by JetHome®