iio:ad7266: Fix broken regulator error handling
Subsystems (2)
PATCH 1/3 iio:ad7266: Fix broken regulator error handling
All regulator_get() variants return either a pointer to a regulator or an ERR_PTR() so testing for NULL makes no sense and may lead to bugs if we use NULL as a valid regulator. Fix this by using IS_ERR() as expected.
--- drivers/iio/adc/ad7266.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7266.c +1 -1
@@ -397,7 +397,7 @@ static int ad7266_probe(struct spi_device *spi) st =iio_priv (indio_dev); st->reg =devm_regulator_get (&spi->dev,"vref" ); -if (!IS_ERR_OR_NULL (st->reg)) { +if (!IS_ERR (st->reg)) { ret =regulator_enable (st->reg);if (ret)return ret;
Signature · 1 line
2.8.1
PATCH 2/3 iio:ad7266: Fix support for optional regulators
The ad7266 driver attempts to support deciding between the use of internal and external power supplies by checking to see if an error is returned when requesting the regulator. This doesn't work with the current code since the driver uses a normal regulator_get() which is for non-optional supplies and so assumes that if a regulator is not provided by the platform then this is a bug in the platform integration and so substitutes a dummy regulator. Use regulator_get_optional() instead which indicates to the framework that the regulator may be absent and provides a dummy regulator instead.
--- drivers/iio/adc/ad7266.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/ad7266.c +1 -1
@@ -396,7 +396,7 @@ static int ad7266_probe(struct spi_device *spi) st =iio_priv (indio_dev); - st->reg =devm_regulator_get (&spi->dev,"vref" ); + st->reg =devm_regulator_get_optional (&spi->dev,"vref" );if (!IS_ERR (st->reg)) { ret =regulator_enable (st->reg);if (ret)
Signature · 1 line
2.8.1
Re: [PATCH 2/3] iio:ad7266: Fix support for optional regulators
Quoted 11 lines · Mark Brown
The ad7266 driver attempts to support deciding between the use of internal and external power supplies by checking to see if an error is returned when requesting the regulator. This doesn't work with the current code since the driver uses a normal
regulator_get()which is for non-optional supplies and so assumes that if a regulator is not provided by the platform then this is a bug in the platform integration and so substitutes a dummy regulator. Useregulator_get_optional()instead which indicates to the framework that the regulator may be absent and provides a dummy regulator instead.Signed-off-by Mark Brown <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks,
Jonathan
Quoted 18 lines
--- drivers/iio/adc/ad7266.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ad7266.c +1
-1@@ -396,7 +396,7 @@ static int ad7266_probe(struct spi_device *spi) st =iio_priv (indio_dev); - st->reg =devm_regulator_get (&spi->dev,"vref" ); + st->reg =devm_regulator_get_optional (&spi->dev,"vref" );if (!IS_ERR (st->reg)) { ret =regulator_enable (st->reg);if (ret)
PATCH 3/3 iio:ad7266: Fix probe deferral for vref
In reply to Mark BrownCurrently the ad7266 driver treats any failure to get vref as though the regulator were not present but this means that if probe deferral is triggered the driver will act as though the regulator were not present. Instead only use the internal reference if we explicitly got -ENODEV which is what is returned for absent regulators.
--- drivers/iio/adc/ad7266.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/adc/ad7266.c +3 -0
@@ -408,6 +408,9 @@ static int ad7266_probe(struct spi_device *spi) st->vref_mv = ret /1000 ; }else { +/* Any other error indicates that the regulator does exist */ +if (PTR_ERR (st->reg) != -ENODEV ) +return PTR_ERR (st->reg);/* Use internal reference */ st->vref_mv =2500 ; }
Signature · 1 line
2.8.1
Re: [PATCH 3/3] iio:ad7266: Fix probe deferral for vref
Quoted 7 lines · Mark Brown
Currently the ad7266 driver treats any failure to get vref as though the regulator were not present but this means that if probe deferral is triggered the driver will act as though the regulator were not present. Instead only use the internal reference if we explicitly got
-ENODEVwhich is what is returned for absent regulators.Signed-off-by Mark Brown <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Lars, these all seems obviously correct to me, but I'll hold that tree for a day or two so still time to comment.
I dread to think how many other missuses we have of these interfaces in the tree...
Jonathan
Quoted 19 lines
--- drivers/iio/adc/ad7266.c | 3 +++ 1 file changed, 3 insertions(+)drivers/iio/adc/ad7266.c +3
-0@@ -408,6 +408,9 @@ static int ad7266_probe(struct spi_device *spi) st->vref_mv = ret /1000 ; }else { +/* Any other error indicates that the regulator does exist */ +if (PTR_ERR (st->reg) != -ENODEV ) +return PTR_ERR (st->reg);/* Use internal reference */ st->vref_mv =2500 ; }
Re: [PATCH 3/3] iio:ad7266: Fix probe deferral for vref
Quoted 2 lines · Jonathan Cameron
I dread to think how many other missuses we have of these interfaces in the tree...
I have agreed with Mark to take a sweep with the broomstick across IIO and make sure we get this right everywhere here.
Yours,
Linus Walleij
Quoted 5 lines · Mark Brown
All
regulator_get()variants return either a pointer to a regulator or anERR_PTR()so testing for NULL makes no sense and may lead to bugs if we use NULL as a valid regulator. Fix this by usingIS_ERR()as expected.Signed-off-by Mark Brown <[email protected]>
Applied to the fixes-togreg branch of iio.git and marked for stable.
Thanks Mark,
Jonathan
Quoted 18 lines
--- drivers/iio/adc/ad7266.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/ad7266.c +1
-1@@ -397,7 +397,7 @@ static int ad7266_probe(struct spi_device *spi) st =iio_priv (indio_dev); st->reg =devm_regulator_get (&spi->dev,"vref" ); -if (!IS_ERR_OR_NULL (st->reg)) { +if (!IS_ERR (st->reg)) { ret =regulator_enable (st->reg);if (ret)return ret;