[PATCH] drivers: adc: fix return value if timeout occurs

Because unsigned integers cannot be negative, timeout variable is never less than zero. Hence, checks in Amlogic Meson ADC driver to detect timeouts always evaluated to false. Fix that.
Signed-off-by: Francois Berder fberder@outlook.fr ---
drivers/adc/meson-saradc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 1a45a3a265..a48200a769 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -192,7 +192,8 @@ meson_saradc_get_fifo_count(struct meson_saradc_priv *priv)
static int meson_saradc_lock(struct meson_saradc_priv *priv) { - uint val, timeout = 10000; + uint val; + int timeout = 10000;
/* prevent BL30 from using the SAR ADC while we are using it */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY, @@ -246,7 +247,8 @@ static int meson_saradc_calib_val(struct meson_saradc_priv *priv, int val)
static int meson_saradc_wait_busy_clear(struct meson_saradc_priv *priv) { - uint regval, timeout = 10000; + uint regval; + int timeout = 10000;
/* * NOTE: we need a small delay before reading the status, otherwise

Hi
On Tue, Mar 1, 2022 at 1:38 PM Francois Berder fberder@outlook.fr wrote:
Because unsigned integers cannot be negative, timeout variable is never less than zero. Hence, checks in Amlogic Meson ADC driver to detect timeouts always evaluated to false. Fix that.
Signed-off-by: Francois Berder fberder@outlook.fr
drivers/adc/meson-saradc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 1a45a3a265..a48200a769 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -192,7 +192,8 @@ meson_saradc_get_fifo_count(struct meson_saradc_priv *priv)
static int meson_saradc_lock(struct meson_saradc_priv *priv) {
uint val, timeout = 10000;
uint val;
int timeout = 10000; /* prevent BL30 from using the SAR ADC while we are using it */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
@@ -246,7 +247,8 @@ static int meson_saradc_calib_val(struct meson_saradc_priv *priv, int val)
Can you use regmap_read_poll_timeout?
Michael
static int meson_saradc_wait_busy_clear(struct meson_saradc_priv *priv) {
uint regval, timeout = 10000;
uint regval;
int timeout = 10000; /* * NOTE: we need a small delay before reading the status, otherwise
-- 2.30.1 (Apple Git-130)

Hi,
On 01/03/2022 13:48, Michael Nazzareno Trimarchi wrote:
Hi
On Tue, Mar 1, 2022 at 1:38 PM Francois Berder fberder@outlook.fr wrote:
Because unsigned integers cannot be negative, timeout variable is never less than zero. Hence, checks in Amlogic Meson ADC driver to detect timeouts always evaluated to false. Fix that.
Signed-off-by: Francois Berder fberder@outlook.fr
drivers/adc/meson-saradc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c index 1a45a3a265..a48200a769 100644 --- a/drivers/adc/meson-saradc.c +++ b/drivers/adc/meson-saradc.c @@ -192,7 +192,8 @@ meson_saradc_get_fifo_count(struct meson_saradc_priv *priv)
static int meson_saradc_lock(struct meson_saradc_priv *priv) {
uint val, timeout = 10000;
uint val;
int timeout = 10000; /* prevent BL30 from using the SAR ADC while we are using it */ regmap_update_bits(priv->regmap, MESON_SAR_ADC_DELAY,
@@ -246,7 +247,8 @@ static int meson_saradc_calib_val(struct meson_saradc_priv *priv, int val)
Can you use regmap_read_poll_timeout?
Good point, it's weird I haven't use it at submission.
Neil
Michael
static int meson_saradc_wait_busy_clear(struct meson_saradc_priv *priv) {
uint regval, timeout = 10000;
uint regval;
int timeout = 10000; /* * NOTE: we need a small delay before reading the status, otherwise
-- 2.30.1 (Apple Git-130)
participants (3)
-
Francois Berder
-
Michael Nazzareno Trimarchi
-
Neil Armstrong