mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: dummy_hcd: fix data corruption with queued requests
@ 2026-03-15  9:03 Sebastian Urban
  2026-03-15 14:44 ` Alan Stern
  0 siblings, 1 reply; 9+ messages in thread
From: Sebastian Urban @ 2026-03-15  9:03 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel, surban

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. 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.

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-03-15 18:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-15  9:03 [PATCH] usb: gadget: dummy_hcd: fix data corruption with queued requests Sebastian Urban
2026-03-15 14:44 ` Alan Stern
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

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®