Skip to contentSkip to conversation

iio:ad7266: Fix broken regulator error handling

PATCH Applied Mark Brown 3 participants 7 messages Jun 20, 2016 – Jun 27, 2016

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

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
index 21e19b60e2b9..835d45db258f 100644
@@ -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
author
#1 lore raw

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
index 835d45db258f..655b36b4e9cb 100644
@@ -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
maintainer Applied
#2 lore raw

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. Use regulator_get_optional() instead which indicates to the framework that the regulator may be absent and provides a dummy regulator instead.

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
index 835d45db258f..655b36b4e9cb 100644
@@ -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)
author
#3 lore raw

PATCH 3/3 iio:ad7266: Fix probe deferral for vref

In reply to 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 -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
index 655b36b4e9cb..2123f0ac2e2a 100644
@@ -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
maintainer Applied
#4 lore raw

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 -ENODEV which is what is returned for absent regulators.

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
index 655b36b4e9cb..2123f0ac2e2a 100644
@@ -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;
 	}
#5 lore raw

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

maintainer Applied
#6 lore raw
In reply to Mark Brown
Quoted 5 lines · Mark Brown

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.

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
index 21e19b60e2b9..835d45db258f 100644
@@ -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;