Skip to content

Commit 02a6982

Browse files
Thinh Nguyengregkh
authored andcommitted
usb: dwc3: gadget: Fix checking for number of TRBs left
The check whether the TRB ring is full or empty in dwc3_calc_trbs_left() is insufficient. It assumes there are active TRBs if there's any request in the started_list. However, that's not the case for requests with a large SG list. That is, if we have a single usb request that requires more TRBs than the total TRBs in the TRB ring, the queued TRBs will be available when all the TRBs in the ring are completed. But the request is only partially completed and remains in the started_list. With the current logic, the TRB ring is empty, but dwc3_calc_trbs_left() returns 0. Fix this by additionally checking for the request->num_trbs for active TRB count. Cc: [email protected] Fixes: 51f1954 ("usb: dwc3: gadget: Fix dwc3_calc_trbs_left()") Signed-off-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/708dc62b56b77da1f704cc2ae9b6ddb1f2dbef1f.1731545781.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5d2fb07 commit 02a6982

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,11 +1230,14 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
12301230
* pending to be processed by the driver.
12311231
*/
12321232
if (dep->trb_enqueue == dep->trb_dequeue) {
1233+
struct dwc3_request *req;
1234+
12331235
/*
1234-
* If there is any request remained in the started_list at
1235-
* this point, that means there is no TRB available.
1236+
* If there is any request remained in the started_list with
1237+
* active TRBs at this point, then there is no TRB available.
12361238
*/
1237-
if (!list_empty(&dep->started_list))
1239+
req = next_request(&dep->started_list);
1240+
if (req && req->num_trbs)
12381241
return 0;
12391242

12401243
return DWC3_TRB_NUM - 1;

0 commit comments

Comments
 (0)