Skip to content

Commit 51f1954

Browse files
Thinh Nguyengregkh
authored andcommitted
usb: dwc3: gadget: Fix dwc3_calc_trbs_left()
We can't depend on the TRB's HWO bit to determine if the TRB ring is "full". A TRB is only available when the driver had processed it, not when the controller consumed and relinquished the TRB's ownership to the driver. Otherwise, the driver may overwrite unprocessed TRBs. This can happen when many transfer events accumulate and the system is slow to process them and/or when there are too many small requests. If a request is in the started_list, that means there is one or more unprocessed TRBs remained. Check this instead of the TRB's HWO bit whether the TRB ring is full. Fixes: c423357 ("usb: dwc3: gadget: prepare TRBs on update transfers too") Cc: <[email protected]> Acked-by: Felipe Balbi <[email protected]> Signed-off-by: Thinh Nguyen <[email protected]> Link: https://lore.kernel.org/r/e91e975affb0d0d02770686afc3a5b9eb84409f6.1629335416.git.Thinh.Nguyen@synopsys.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 662b932 commit 51f1954

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/usb/dwc3/gadget.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -940,19 +940,19 @@ static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index)
940940

941941
static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
942942
{
943-
struct dwc3_trb *tmp;
944943
u8 trbs_left;
945944

946945
/*
947-
* If enqueue & dequeue are equal than it is either full or empty.
948-
*
949-
* One way to know for sure is if the TRB right before us has HWO bit
950-
* set or not. If it has, then we're definitely full and can't fit any
951-
* more transfers in our ring.
946+
* If the enqueue & dequeue are equal then the TRB ring is either full
947+
* or empty. It's considered full when there are DWC3_TRB_NUM-1 of TRBs
948+
* pending to be processed by the driver.
952949
*/
953950
if (dep->trb_enqueue == dep->trb_dequeue) {
954-
tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue);
955-
if (tmp->ctrl & DWC3_TRB_CTRL_HWO)
951+
/*
952+
* If there is any request remained in the started_list at
953+
* this point, that means there is no TRB available.
954+
*/
955+
if (!list_empty(&dep->started_list))
956956
return 0;
957957

958958
return DWC3_TRB_NUM - 1;

0 commit comments

Comments
 (0)