diff mbox series

[v3,1/5] staging: iio: adc: ad7192: fail probe on get_voltage

Message ID 20200212161721.16200-2-alexandru.tachici@analog.com (mailing list archive)
State New, archived
Headers show
Series iio: adc: ad7192: move out of staging | expand

Commit Message

Alexandru Tachici Feb. 12, 2020, 4:17 p.m. UTC
This patch makes the ad7192_probe fail in case
regulator_get_voltage will return an error or voltage
is set to 0.

Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
---
 drivers/staging/iio/adc/ad7192.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Jonathan Cameron Feb. 14, 2020, 3:40 p.m. UTC | #1
On Wed, 12 Feb 2020 18:17:17 +0200
Alexandru Tachici <alexandru.tachici@analog.com> wrote:

> This patch makes the ad7192_probe fail in case
> regulator_get_voltage will return an error or voltage
> is set to 0.
> 
> Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com>
There are some corner cases around this that we may meet
in the future. Particularly if someone uses a variable reg
to provide this voltage.  However, we can fix those when
we come to them.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/staging/iio/adc/ad7192.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
> index bf3e2a9cc07f..41da8b4cdc48 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -899,10 +899,13 @@ static int ad7192_probe(struct spi_device *spi)
>  
>  	voltage_uv = regulator_get_voltage(st->avdd);
>  
> -	if (voltage_uv)
> +	if (voltage_uv > 0) {
>  		st->int_vref_mv = voltage_uv / 1000;
> -	else
> +	} else {
> +		ret = voltage_uv;
>  		dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
> +		goto error_disable_avdd;
> +	}
>  
>  	spi_set_drvdata(spi, indio_dev);
>  	st->devid = spi_get_device_id(spi)->driver_data;
diff mbox series

Patch

diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index bf3e2a9cc07f..41da8b4cdc48 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -899,10 +899,13 @@  static int ad7192_probe(struct spi_device *spi)
 
 	voltage_uv = regulator_get_voltage(st->avdd);
 
-	if (voltage_uv)
+	if (voltage_uv > 0) {
 		st->int_vref_mv = voltage_uv / 1000;
-	else
+	} else {
+		ret = voltage_uv;
 		dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
+		goto error_disable_avdd;
+	}
 
 	spi_set_drvdata(spi, indio_dev);
 	st->devid = spi_get_device_id(spi)->driver_data;