]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
usb: dwc3: gadget: Reclaim extra TRBs after request completion
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Thu, 24 Sep 2020 08:21:24 +0000 (01:21 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 18 Nov 2020 18:18:41 +0000 (19:18 +0100)
[ Upstream commit 690e5c2dc29f8891fcfd30da67e0d5837c2c9df5 ]

An SG request may be partially completed (due to no available TRBs).
Don't reclaim extra TRBs and clear the needs_extra_trb flag until the
request is fully completed. Otherwise, the driver will reclaim the wrong
TRB.

Cc: stable@vger.kernel.org
Fixes: 1f512119a08c ("usb: dwc3: gadget: add remaining sg entries to ring")
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/usb/dwc3/gadget.c

index f24cfb3a6907b2d8f8dfe1199732d1279a17fb58..6ab5c48f5d8737616954a7f3c622453309059a5e 100644 (file)
@@ -2386,6 +2386,11 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
                ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
                                status);
 
+       req->request.actual = req->request.length - req->remaining;
+
+       if (!dwc3_gadget_ep_request_completed(req))
+               goto out;
+
        if (req->needs_extra_trb) {
                unsigned int maxp = usb_endpoint_maxp(dep->endpoint.desc);
 
@@ -2401,11 +2406,6 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
                req->needs_extra_trb = false;
        }
 
-       req->request.actual = req->request.length - req->remaining;
-
-       if (!dwc3_gadget_ep_request_completed(req))
-               goto out;
-
        dwc3_gadget_giveback(dep, req, status);
 
 out: