usb: dwc3: gadget: prevent dwc3_request from being queued twice
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Fri, 11 Jan 2019 10:58:52 +0000 (12:58 +0200)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 28 Jan 2019 10:53:15 +0000 (12:53 +0200)
Queueing the same request twice can introduce hard-to-debug
problems. At least one function driver - Android's f_mtp.c - is known
to cause this problem.

While that function is out-of-tree, this is a problem that's easy
enough to avoid.

Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/gadget.c

index 9fde48656044c48054d5778164c6fd1fc2d8a12b..064d5161c4838deae8d37853bfbbb8bf071f5e7d 100644 (file)
@@ -1437,6 +1437,11 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req)
                                &req->request, req->dep->name))
                return -EINVAL;
 
+       if (WARN(req->status < DWC3_REQUEST_STATUS_COMPLETED,
+                               "%s: request %pK already in flight\n",
+                               dep->name, &req->request))
+               return -EINVAL;
+
        pm_runtime_get(dwc->dev);
 
        req->request.actual     = 0;