| From 690e5c2dc29f8891fcfd30da67e0d5837c2c9df5 Mon Sep 17 00:00:00 2001 |
| From: Thinh Nguyen <Thinh.Nguyen@synopsys.com> |
| Date: Thu, 24 Sep 2020 01:21:24 -0700 |
| Subject: usb: dwc3: gadget: Reclaim extra TRBs after request completion |
| |
| From: Thinh Nguyen <Thinh.Nguyen@synopsys.com> |
| |
| commit 690e5c2dc29f8891fcfd30da67e0d5837c2c9df5 upstream. |
| |
| 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| --- |
| drivers/usb/dwc3/gadget.c | 10 +++++----- |
| 1 file changed, 5 insertions(+), 5 deletions(-) |
| |
| --- a/drivers/usb/dwc3/gadget.c |
| +++ b/drivers/usb/dwc3/gadget.c |
| @@ -2732,6 +2732,11 @@ static int dwc3_gadget_ep_cleanup_comple |
| 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); |
| |
| @@ -2747,11 +2752,6 @@ static int dwc3_gadget_ep_cleanup_comple |
| 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: |