UPSTREAM: usb: dwc3: gadget: single return point on generic commands
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Mon, 23 May 2016 11:06:07 +0000 (14:06 +0300)
committerHuang, Tao <huangtao@rock-chips.com>
Tue, 16 Aug 2016 12:48:19 +0000 (20:48 +0800)
Just like we did for endpoint commands, let's use a
single return point for generic commands as
well. This aids readability.

Change-Id: Idc1bf9bc4fe2e50cb0841e9a8483c24346b4974d
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
(cherry picked from commit 0fe886cdb07aeaf75a61154f34abc8dd6860978e)

drivers/usb/dwc3/gadget.c

index d8952ce7112ce2028c5cfc98908b4d25b759b717..74a1489e57153bf893d9f2a5686a1443c4992a13 100644 (file)
@@ -207,6 +207,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
 {
        u32             timeout = 500;
+       int             ret = 0;
        u32             reg;
 
        trace_dwc3_gadget_generic_cmd(cmd, param);
@@ -221,22 +222,20 @@ int dwc3_send_gadget_generic_command(struct dwc3 *dwc, unsigned cmd, u32 param)
                                        "Command Complete --> %d",
                                        DWC3_DGCMD_STATUS(reg));
                        if (DWC3_DGCMD_STATUS(reg))
-                               return -EINVAL;
-                       return 0;
+                               ret = -EINVAL;
+                       break;
                }
 
-               /*
-                * We can't sleep here, because it's also called from
-                * interrupt context.
-                */
-               timeout--;
-               if (!timeout) {
-                       dwc3_trace(trace_dwc3_gadget,
-                                       "Command Timed Out");
-                       return -ETIMEDOUT;
-               }
                udelay(1);
-       } while (1);
+       } while (timeout--);
+
+       if (!timeout) {
+               dwc3_trace(trace_dwc3_gadget,
+                               "Command Timed Out");
+               ret = -ETIMEDOUT;
+       }
+
+       return ret;
 }
 
 static int __dwc3_gadget_wakeup(struct dwc3 *dwc);