]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
usb: dwc3: gadget: simplify run_stop() break condition
authorFelipe Balbi <felipe.balbi@linux.intel.com>
Thu, 9 Jun 2016 13:47:05 +0000 (16:47 +0300)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Tue, 21 Jun 2016 07:38:43 +0000 (10:38 +0300)
it's clear now that when is_on=true, we must loop
until DWC3_DSTS_DEVCTRLHLT clears; while when
is_on=false we must loop until DWC3_DSTS_DEVCTRLHLT
gets set.

Instead of adding actual if() statements, we can
rely on XOR operation to evaluate to true only when
the above conditions apply. Then, we can move the
break condition back to the while() statement
together with our timeout check and the resulting
code is very compact and simpler to read.

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

index 9b9367b22ad3e7c0bf904e52ae4ea0f1df72fa8b..0afaa9d585629831ffd70eb6e30c8a5e972418cf 100644 (file)
@@ -1574,14 +1574,8 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 
        do {
                reg = dwc3_readl(dwc->regs, DWC3_DSTS);
-               if (is_on) {
-                       if (!(reg & DWC3_DSTS_DEVCTRLHLT))
-                               break;
-               } else {
-                       if (reg & DWC3_DSTS_DEVCTRLHLT)
-                               break;
-               }
-       } while (--timeout);
+               reg &= DWC3_DSTS_DEVCTRLHLT;
+       } while (--timeout && !(!is_on ^ !reg));
 
        if (!timeout)
                return -ETIMEDOUT;