Skip to content

Commit b0f27fc

Browse files
commodojic23
authored andcommitted
iio: adc: ad7192: handle regulator voltage error first
This change fixes a corner-case, where for a zero regulator value, the driver would exit early, initializing the driver only partially. The driver would be in an unknown state. This change reworks the code to check regulator_voltage() return value for negative (error) first, and return early. This is the more common idiom. Also, this change is removing the 'voltage_uv' variable and using the 'ret' value directly. The only place where 'voltage_uv' is being used is to compute the internal reference voltage, and the type of this variable is 'int' (same are for 'ret'). Using only 'ret' avoids having to assign it on the error path. Fixes: ab0afa6 ("staging: iio: adc: ad7192: fail probe on get_voltage") Cc: Alexandru Tachici <[email protected]> Signed-off-by: Alexandru Ardelean <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Cc: <[email protected]>
1 parent e32fe6d commit b0f27fc

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

drivers/iio/adc/ad7192.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ static int ad7192_probe(struct spi_device *spi)
912912
{
913913
struct ad7192_state *st;
914914
struct iio_dev *indio_dev;
915-
int ret, voltage_uv = 0;
915+
int ret;
916916

917917
if (!spi->irq) {
918918
dev_err(&spi->dev, "no IRQ?\n");
@@ -949,15 +949,12 @@ static int ad7192_probe(struct spi_device *spi)
949949
goto error_disable_avdd;
950950
}
951951

952-
voltage_uv = regulator_get_voltage(st->avdd);
953-
954-
if (voltage_uv > 0) {
955-
st->int_vref_mv = voltage_uv / 1000;
956-
} else {
957-
ret = voltage_uv;
952+
ret = regulator_get_voltage(st->avdd);
953+
if (ret < 0) {
958954
dev_err(&spi->dev, "Device tree error, reference voltage undefined\n");
959955
goto error_disable_avdd;
960956
}
957+
st->int_vref_mv = ret / 1000;
961958

962959
spi_set_drvdata(spi, indio_dev);
963960
st->chip_info = of_device_get_match_data(&spi->dev);

0 commit comments

Comments
 (0)