Re: [PATCH 1/3] usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs

From: Thinh Nguyen
Date: Mon Jun 23 2025 - 18:42:05 EST


On Sat, Jun 21, 2025, Johannes Schneider wrote:
> Commit 61440628a4ff ("usb: dwc3: gadget: Cleanup SG handling") updated
> the TRB reclaim path to use the TRB CHN (Chain) bit to determine whether
> a TRB was part of a chain. However, this inadvertently changed the
> behavior of reclaiming the final TRB in some scatter-gather or short
> transfer cases.
>
> In particular, if the final TRB did not have the CHN bit set, the
> cleanup path could incorrectly skip clearing the HWO (Hardware Own)
> bit, leaving stale TRBs in the ring. This resulted in broken data
> transfer completions in userspace, notably for MTP over FunctionFS.
>
> Fix this by unconditionally clearing the HWO bit during TRB reclaim,
> regardless of the CHN bit state. This restores correct behavior
> especially for transfers that require ZLPs or end on non-CHN TRBs.
>
> Fixes: 61440628a4ff ("usb: dwc3: gadget: Cleanup SG handling")
> Signed-off-by: Johannes Schneider <johannes.schneider@xxxxxxxxxxxxxxxxxxxx>
> ---
> drivers/usb/dwc3/gadget.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 321361288935db4b773cd06235a16670a6adda1a..99fbd29d8f46d30df558ceb23d2afe7187b4244c 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -3516,7 +3516,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,
> * We're going to do that here to avoid problems of HW trying
> * to use bogus TRBs for transfers.
> */
> - if (chain && (trb->ctrl & DWC3_TRB_CTRL_HWO))
> + if (trb->ctrl & DWC3_TRB_CTRL_HWO)
> trb->ctrl &= ~DWC3_TRB_CTRL_HWO;
>
> /*
>
> --
> 2.34.1
>

Thanks for the catch. Please also Cc stable.

Acked-by: Thinh Nguyen <Thinh.Nguyen@xxxxxxxxxxxx>

BR,,
Thinh