From 2007d5815ef881e0e83a7e47506bdce878389f17 Mon Sep 17 00:00:00 2001 From: William Wu Date: Tue, 26 Apr 2022 20:32:21 +0800 Subject: [PATCH] usb: dwc3: gadget: properly skip over trbs on ep_dequeue The commit a7027ca69d82 ("usb: dwc3: gadget: Give back staled requests") move all started request to cancelled list and expect to give back all the started requests. However, it fails to give back the started requests if the dep->flags isn't set to DWC3_EP_TRANSFER_STARTED, in this case, we need to skip the trbs and giveback the req. And we also need to skip the trbs of the req in the pending_list to make the dequeue pointers useless. Signed-off-by: William Wu Change-Id: I123ff779d5e2933449581f8b570e2e6ad6b75458 --- drivers/usb/dwc3/gadget.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index ac7265de77d8..b19b67d8d399 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2018,6 +2018,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry(r, &dep->pending_list, list) { if (r == req) { + dwc3_gadget_ep_skip_trbs(dep, req); dwc3_gadget_giveback(dep, req, -ECONNRESET); goto out; } @@ -2025,8 +2026,6 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, list_for_each_entry(r, &dep->started_list, list) { if (r == req) { - struct dwc3_request *t; - /* wait until it is processed */ dwc3_stop_active_transfer(dep, true, true); @@ -2034,12 +2033,15 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep, * Remove any started request if the transfer is * cancelled. */ - list_for_each_entry_safe(r, t, &dep->started_list, list) - dwc3_gadget_move_cancelled_request(r, - DWC3_REQUEST_STATUS_DEQUEUED); + dwc3_gadget_move_cancelled_request(r, DWC3_REQUEST_STATUS_DEQUEUED); dep->flags &= ~DWC3_EP_WAIT_TRANSFER_COMPLETE; + if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) { + dwc3_gadget_ep_skip_trbs(dep, req); + dwc3_gadget_giveback(dep, req, -ECONNRESET); + } + goto out; } }