diff mbox series

drivers: adc: fix return value if timeout occurs

Message ID HE1P192MB00097C66713AB8FE99E5E904DA029@HE1P192MB0009.EURP192.PROD.OUTLOOK.COM
State Superseded
Delegated to: Tom Rini
Headers show
Series drivers: adc: fix return value if timeout occurs | expand

Commit Message

Francois Berder March 1, 2022, 12:34 p.m. UTC
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(-)

Comments

Michael Nazzareno Trimarchi March 1, 2022, 12:48 p.m. UTC | #1
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)
>
Neil Armstrong March 1, 2022, 1:08 p.m. UTC | #2
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)
>>
> 
>
diff mbox series

Patch

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