From: Varadarajan Narayanan Date: Wed, 15 Jan 2025 06:20:44 +0000 (+0530) Subject: usb: dwc3: core: Fix timeout check X-Git-Tag: v2025.07-rc3~1^2~2 X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=068f83499c2f8299c6172c511ec875eef2b26a6f;p=pandora-u-boot.git usb: dwc3: core: Fix timeout check dwc3_core_init loops 'timeout' times to check if the IP block is out of reset using 'while (timeout--)'. If there is some issue and the block doesn't come out of reset, the loop will run till 'timeout' becomes zero and the post decrement operator would set timeout to 0xffffffff. Though the IP block is not out reset, the subsequent if check 'if !timeout' would fail as timeout is not equal to zero and the function proceeds with the initialization. Use poll API instead to resolve this. Signed-off-by: Varadarajan Narayanan Reviewed-by: Mattijs Korpershoek Reviewed-by: Caleb Connolly --- diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index a35b8c2f646..847fa1f82c3 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -587,7 +588,6 @@ static void dwc3_set_incr_burst_type(struct dwc3 *dwc) */ static int dwc3_core_init(struct dwc3 *dwc) { - unsigned long timeout; u32 hwparams4 = dwc->hwparams.hwparams4; u32 reg; int ret; @@ -610,15 +610,11 @@ static int dwc3_core_init(struct dwc3 *dwc) } /* issue device SoftReset too */ - timeout = 5000; dwc3_writel(dwc->regs, DWC3_DCTL, DWC3_DCTL_CSFTRST); - while (timeout--) { - reg = dwc3_readl(dwc->regs, DWC3_DCTL); - if (!(reg & DWC3_DCTL_CSFTRST)) - break; - }; - - if (!timeout) { + ret = read_poll_timeout(dwc3_readl, reg, + !(reg & DWC3_DCTL_CSFTRST), + 1, 5000, dwc->regs, DWC3_DCTL); + if (ret) { dev_err(dwc->dev, "Reset Timed Out\n"); ret = -ETIMEDOUT; goto err0;