Message ID | 20200205171511.25912-2-alexandru.tachici@analog.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | iio: adc: ad7192: move out of staging | expand |
On Wed, 5 Feb 2020 19:15:07 +0200 Alexandru Tachici <alexandru.tachici@analog.com> wrote: > This patch makes the ad7192_probe fail in case > regulator_get_voltage will return an error. > > Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> There is a subtlety in here we should handle. > --- > drivers/staging/iio/adc/ad7192.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c > index bf3e2a9cc07f..4780ddf99b13 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); > I had to dig a bit to check this as it's not documented. regulator_get_voltage returns negative for error, not 0. 0 typically means the voltage has not been set or has been explicitly set to 0. So if it is set to 0 I suppose we could try setting it as it might be a variable high precision reference? Perhaps for now just spitting out an error is the best plan. > - if (voltage_uv) > + if (voltage_uv) { > 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; > @@ -957,6 +960,7 @@ static int ad7192_probe(struct spi_device *spi) > ret = iio_device_register(indio_dev); > if (ret < 0) > goto error_disable_clk; > + We shouldn't have stray white space changes in a patch making a real change. Thanks, Jonathan > return 0; > > error_disable_clk:
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c index bf3e2a9cc07f..4780ddf99b13 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) { 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; @@ -957,6 +960,7 @@ static int ad7192_probe(struct spi_device *spi) ret = iio_device_register(indio_dev); if (ret < 0) goto error_disable_clk; + return 0; error_disable_clk:
This patch makes the ad7192_probe fail in case regulator_get_voltage will return an error. Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> --- drivers/staging/iio/adc/ad7192.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)