[PATCH v1] usb: dwc3: core: Fix timeout check

neil.armstrong at linaro.org neil.armstrong at linaro.org
Fri Jan 10 10:52:53 CET 2025


On 10/01/2025 08:43, Varadarajan Narayanan wrote:
> 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.
> 
> Make this a pre decrement to address this.
> 
> Signed-off-by: Varadarajan Narayanan <quic_varada at quicinc.com>
> ---
>   drivers/usb/dwc3/core.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index a35b8c2f64..8f58e4ea2d 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -612,7 +612,7 @@ 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--) {
> +	while (--timeout) {
>   		reg = dwc3_readl(dwc->regs, DWC3_DCTL);
>   		if (!(reg & DWC3_DCTL_CSFTRST))
>   			break;

Good catch !

Reviewed-by: Neil Armstrong <neil.armstrong at linaro.org>


More information about the U-Boot mailing list