]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
adc: meson-saradc: uint cannot be less than zero
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 22 Jul 2025 14:06:14 +0000 (15:06 +0100)
committerNeil Armstrong <neil.armstrong@linaro.org>
Tue, 30 Sep 2025 18:32:15 +0000 (20:32 +0200)
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 <andrew.goodbody@linaro.org>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Link: https://lore.kernel.org/r/20250722-meson_saradc-v1-1-1ab45d53da9d@linaro.org
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
drivers/adc/meson-saradc.c

index 60e348968fb54e5e3172738ae1292182621a948a..0144ff828c559e3f9c88bc6a279990a589c952fa 100644 (file)
@@ -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, &regval);
-       } 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;