diff mbox series

[v2,04/12] iio: adc: ad7192: handle zero Avdd regulator value as error

Message ID 20210511071831.576145-5-aardelean@deviqon.com (mailing list archive)
State Superseded
Headers show
Series ad_sigma_delta: convert all drivers to device-managed | expand

Commit Message

Alexandru Ardelean May 11, 2021, 7:18 a.m. UTC
This change fixes a corner-case, where the returned voltage is actually
zero. This is also what patch ab0afa65bbc7 ("staging: iio: adc: ad7192:
fail probe on get_voltage") was trying to do.

But as Jonathan pointed out, a zero-value would signal that the probe has
succeeded, putting the driver is a semi-initialized state.

Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage")
Cc: Alexandru Tachici <alexandru.tachici@analog.com>
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
 drivers/iio/adc/ad7192.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jonathan Cameron May 11, 2021, 2:13 p.m. UTC | #1
On Tue, 11 May 2021 10:18:23 +0300
Alexandru Ardelean <aardelean@deviqon.com> wrote:

> This change fixes a corner-case, where the returned voltage is actually
> zero. This is also what patch ab0afa65bbc7 ("staging: iio: adc: ad7192:
> fail probe on get_voltage") was trying to do.
> 
> But as Jonathan pointed out, a zero-value would signal that the probe has
> succeeded, putting the driver is a semi-initialized state.
> 
> Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage")
> Cc: Alexandru Tachici <alexandru.tachici@analog.com>
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>

Given that voltage_uv == 1 would result in a situation no worse than
for voltage_uv == 0 perhaps we should just change the following condition to

if (voltage_uv >= 0)  ?

Jonathan

> ---
>  drivers/iio/adc/ad7192.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> index d3be67aa0522..79df54e0dc96 100644
> --- a/drivers/iio/adc/ad7192.c
> +++ b/drivers/iio/adc/ad7192.c
> @@ -950,6 +950,11 @@ static int ad7192_probe(struct spi_device *spi)
>  	}
>  
>  	voltage_uv = regulator_get_voltage(st->avdd);
> +	if (voltage_uv == 0) {
> +		ret = -EINVAL;
> +		dev_err(&spi->dev, "Zero value provided for AVdd supply\n");
> +		goto error_disable_avdd;
> +	}
>  
>  	if (voltage_uv > 0) {
>  		st->int_vref_mv = voltage_uv / 1000;
Alexandru Ardelean May 12, 2021, 6:28 a.m. UTC | #2
On Tue, 11 May 2021 at 17:12, Jonathan Cameron <jic23@kernel.org> wrote:
>
> On Tue, 11 May 2021 10:18:23 +0300
> Alexandru Ardelean <aardelean@deviqon.com> wrote:
>
> > This change fixes a corner-case, where the returned voltage is actually
> > zero. This is also what patch ab0afa65bbc7 ("staging: iio: adc: ad7192:
> > fail probe on get_voltage") was trying to do.
> >
> > But as Jonathan pointed out, a zero-value would signal that the probe has
> > succeeded, putting the driver is a semi-initialized state.
> >
> > Fixes: ab0afa65bbc7 ("staging: iio: adc: ad7192: fail probe on get_voltage")
> > Cc: Alexandru Tachici <alexandru.tachici@analog.com>
> > Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
>
> Given that voltage_uv == 1 would result in a situation no worse than
> for voltage_uv == 0 perhaps we should just change the following condition to
>
> if (voltage_uv >= 0)  ?

hmmm, you're right;
i think had some narrow vision about this;

will send a v3

>
> Jonathan
>
> > ---
> >  drivers/iio/adc/ad7192.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
> > index d3be67aa0522..79df54e0dc96 100644
> > --- a/drivers/iio/adc/ad7192.c
> > +++ b/drivers/iio/adc/ad7192.c
> > @@ -950,6 +950,11 @@ static int ad7192_probe(struct spi_device *spi)
> >       }
> >
> >       voltage_uv = regulator_get_voltage(st->avdd);
> > +     if (voltage_uv == 0) {
> > +             ret = -EINVAL;
> > +             dev_err(&spi->dev, "Zero value provided for AVdd supply\n");
> > +             goto error_disable_avdd;
> > +     }
> >
> >       if (voltage_uv > 0) {
> >               st->int_vref_mv = voltage_uv / 1000;
>
diff mbox series

Patch

diff --git a/drivers/iio/adc/ad7192.c b/drivers/iio/adc/ad7192.c
index d3be67aa0522..79df54e0dc96 100644
--- a/drivers/iio/adc/ad7192.c
+++ b/drivers/iio/adc/ad7192.c
@@ -950,6 +950,11 @@  static int ad7192_probe(struct spi_device *spi)
 	}
 
 	voltage_uv = regulator_get_voltage(st->avdd);
+	if (voltage_uv == 0) {
+		ret = -EINVAL;
+		dev_err(&spi->dev, "Zero value provided for AVdd supply\n");
+		goto error_disable_avdd;
+	}
 
 	if (voltage_uv > 0) {
 		st->int_vref_mv = voltage_uv / 1000;