]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
usb: dwc3: gadget: Fix TRB reclaim logic for short transfers and ZLPs
authorSCHNEIDER Johannes <johannes.schneider@leica-geosystems.com>
Wed, 25 Jun 2025 07:49:16 +0000 (07:49 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 28 Jun 2025 15:19:56 +0000 (17:19 +0200)
Commit 96c7bf8f6b3e ("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@leica-geosystems.com>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Cc: stable <stable@kernel.org>
Link: https://lore.kernel.org/r/AM8PR06MB7521A29A8863C838B54987B6BC7BA@AM8PR06MB7521.eurprd06.prod.outlook.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/dwc3/gadget.c

index b6b63b530148a17478b374b3c6b5c5254364f0e4..74968f93d4a3538ef77e64270c45365b21366a2c 100644 (file)
@@ -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;
 
        /*