]> git.itanic.dy.fi Git - linux-stable/commitdiff
usb: dwc3: gadget: delay unmap of bounced requests
authorJanusz Dziedzic <januszx.dziedzic@intel.com>
Mon, 13 Mar 2017 12:11:32 +0000 (14:11 +0200)
committerJiri Slaby <jslaby@suse.cz>
Fri, 28 Apr 2017 17:30:37 +0000 (19:30 +0200)
commit de288e36fe33f7e06fa272bc8e2f85aa386d99aa upstream.

In the case of bounced ep0 requests, we must delay DMA operation until
after ->complete() otherwise we might overwrite contents of req->buf.

This caused problems with RNDIS gadget.

Signed-off-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
drivers/usb/dwc3/gadget.c

index f4a36f4669bbadc5c591425e05bfacfbc92b96b1..b1b833843b9ae00809aeef487f8d52e6c95ec77d 100644 (file)
@@ -221,6 +221,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
                int status)
 {
        struct dwc3                     *dwc = dep->dwc;
+       unsigned int                    unmap_after_complete = false;
        int                             i;
 
        if (req->queued) {
@@ -245,11 +246,19 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
        if (req->request.status == -EINPROGRESS)
                req->request.status = status;
 
-       if (dwc->ep0_bounced && dep->number <= 1)
+       /*
+        * NOTICE we don't want to unmap before calling ->complete() if we're
+        * dealing with a bounced ep0 request. If we unmap it here, we would end
+        * up overwritting the contents of req->buf and this could confuse the
+        * gadget driver.
+        */
+       if (dwc->ep0_bounced && dep->number <= 1) {
                dwc->ep0_bounced = false;
-
-       usb_gadget_unmap_request(&dwc->gadget, &req->request,
-                       req->direction);
+               unmap_after_complete = true;
+       } else {
+               usb_gadget_unmap_request(&dwc->gadget,
+                               &req->request, req->direction);
+       }
 
        dev_dbg(dwc->dev, "request %p from %s completed %d/%d ===> %d\n",
                        req, dep->name, req->request.actual,
@@ -258,6 +267,10 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
        spin_unlock(&dwc->lock);
        req->request.complete(&dep->endpoint, &req->request);
        spin_lock(&dwc->lock);
+
+       if (unmap_after_complete)
+               usb_gadget_unmap_request(&dwc->gadget,
+                               &req->request, req->direction);
 }
 
 static const char *dwc3_gadget_ep_cmd_string(u8 cmd)