From: Felipe Balbi Date: Thu, 9 Jun 2016 13:47:05 +0000 (+0300) Subject: UPSTREAM: usb: dwc3: gadget: simplify run_stop() break condition X-Git-Tag: firefly_0821_release~1777 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=13f2374f1b1b13f6fd1760987df7066dda6420b1;p=firefly-linux-kernel-4.4.55.git UPSTREAM: usb: dwc3: gadget: simplify run_stop() break condition 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. Change-Id: Id540c7422cd1d7e00120c26353d99e2e9888ea26 Signed-off-by: Felipe Balbi Signed-off-by: Wu Liang feng (cherry picked from commit b6d4e16e831376b676edb3463f2bdaa192e5f7be) --- diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 92abd5e382fe..0400d3f9ba8f 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1584,14 +1584,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;