Re: [PATCH] adc: meson-saradc: uint cannot be less than zero
Andrew Goodbody <[email protected]> Thu, 7 Aug 2025 16:07:04 +0100
| Newsgroups | io.groups.u-boot-amlogic,org.u-boot-project.lists.u-boot |
|---|---|
| Message-ID | <[email protected]> |
On 24/07/2025 09:30, Neil Armstrong wrote: > On 22/07/2025 16:06, Andrew Goodbody wrote: >> timeout is declared as a uint but then tested for being less than zero >> which must always fail. Change the while loop for a pre-decrement on >> timeout and test timeout for being zero. >> >> This issue was found by Smatch. >> >> Signed-off-by: Andrew Goodbody <[email protected]> >> --- >> drivers/adc/meson-saradc.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c >> index 60e348968fb..0144ff828c5 100644 >> --- a/drivers/adc/meson-saradc.c >> +++ b/drivers/adc/meson-saradc.c >> @@ -205,9 +205,9 @@ static int meson_saradc_lock(struct >> meson_saradc_priv *priv) >> do { >> udelay(1); >> regmap_read(priv->regmap, MESON_SAR_ADC_DELAY, &val); >> - } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && timeout--); >> + } while (val & MESON_SAR_ADC_DELAY_BL30_BUSY && --timeout); >> - if (timeout < 0) { >> + if (!timeout) { >> printf("Timeout while waiting for BL30 unlock\n"); >> return -ETIMEDOUT; >> } >> @@ -256,9 +256,9 @@ static int meson_saradc_wait_busy_clear(struct >> meson_saradc_priv *priv) >> do { >> udelay(1); >> regmap_read(priv->regmap, MESON_SAR_ADC_REG0, ®val); >> - } while (FIELD_GET(MESON_SAR_ADC_REG0_BUSY_MASK, regval) && >> timeout--); >> + } while (FIELD_GET(MESON_SAR_ADC_REG0_BUSY_MASK, regval) && -- >> timeout); >> - if (timeout < 0) >> + if (!timeout) >> return -ETIMEDOUT; >> return 0; >> >> --- >> base-commit: bd0ade7d090a334b3986936d63a34001d99722ad >> change-id: 20250722-meson_saradc-4bba9dc18333 >> >> Best regards, > > Reviewed-by: Neil Armstrong <[email protected]> Is there anything else needed before this can be merged please? Thanks, Andrew