usb: dwc3: gadget: properly check ep cmd
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 22 Sep 2016 09:25:28 +0000 (12:25 +0300)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 31 Oct 2016 09:15:34 +0000 (11:15 +0200)
The cmd argument we pass to
dwc3_send_gadget_ep_cmd() could contain extra
arguments embedded. When checking for StartTransfer
command, we need to make sure to match only lower 4
bits which contain the actual command and ignore the
rest.

Reported-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
drivers/usb/dwc3/core.h
drivers/usb/dwc3/gadget.c

index 6b60e42..99fa8b8 100644 (file)
 #define DWC3_DEPCMD_SETTRANSFRESOURCE  (0x02 << 0)
 #define DWC3_DEPCMD_SETEPCONFIG                (0x01 << 0)
 
+#define DWC3_DEPCMD_CMD(x)             ((x) & 0xf)
+
 /* The EP number goes 0..31 so ep0 is always out and ep1 is always in */
 #define DWC3_DALEPENA_EP(n)            (1 << n)
 
index b3687e2..4ed8b34 100644 (file)
@@ -258,7 +258,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd,
                }
        }
 
-       if (cmd == DWC3_DEPCMD_STARTTRANSFER) {
+       if (DWC3_DEPCMD_CMD(cmd) == DWC3_DEPCMD_STARTTRANSFER) {
                int             needs_wakeup;
 
                needs_wakeup = (dwc->link_state == DWC3_LINK_STATE_U1 ||