Paul Zimmerman <pauldzim@xxxxxxxxx> writes: > Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> writes: > >> instead of having infinite loop and always checking >> timeout value as a break condition, we can just >> decrement timeout inside while's condition. >> >> Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> >> --- >> drivers/usb/dwc3/gadget.c | 18 ++++++------------ >> 1 file changed, 6 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c >> index efb758e5c6c7..8a16d8b2da8a 100644 >> --- a/drivers/usb/dwc3/gadget.c >> +++ b/drivers/usb/dwc3/gadget.c >> @@ -327,19 +327,13 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, >> >> break; >> } >> + } while (timeout--); > > When 'timeout' reaches 0, the post-decrement means the value will be -1 when > the loop exits. > >> >> - /* >> - * We can't sleep here, because it is also called from >> - * interrupt context. >> - */ >> - timeout--; >> - if (!timeout) { >> - dwc3_trace(trace_dwc3_gadget, >> - "Command Timed Out"); >> - ret = -ETIMEDOUT; >> - break; >> - } >> - } while (1); >> + if (timeout == 0) { > > But here you are testing against 0 instead of -1. good point :-) Fixed: 8<-------------------------------------------------------------------------- From 98ee80f8821471a0dba38f2207fbb96c1b6c538a Mon Sep 17 00:00:00 2001 From: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> Date: Mon, 23 May 2016 13:53:34 +0300 Subject: [PATCH] usb: dwc3: gadget: loop while (timeout) instead of having infinite loop and always checking timeout value as a break condition, we can just decrement timeout inside while's condition. Signed-off-by: Felipe Balbi <felipe.balbi@xxxxxxxxxxxxxxx> --- drivers/usb/dwc3/gadget.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index efb758e5c6c7..ca8269646b72 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -327,19 +327,13 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned cmd, break; } + } while (--timeout); - /* - * We can't sleep here, because it is also called from - * interrupt context. - */ - timeout--; - if (!timeout) { - dwc3_trace(trace_dwc3_gadget, - "Command Timed Out"); - ret = -ETIMEDOUT; - break; - } - } while (1); + if (timeout == 0) { + dwc3_trace(trace_dwc3_gadget, + "Command Timed Out"); + ret = -ETIMEDOUT; + } if (unlikely(susphy)) { reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0)); -- 2.8.3 -- balbi
Attachment:
signature.asc
Description: PGP signature