Skip to contentSkip to conversation

iio: ad7292: Prevent regulator double disable

PATCH In review Matti Vaittinen 3 participants 3 messages Aug 19, 2022 – Aug 20, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: ad7292: Prevent regulator double disable

The ad7292 tries to add an devm_action for disabling a regulator at device detach using devm_add_action_or_reset(). The devm_add_action_or_reset() does call the release function should adding action fail. The driver inspects the value returned by devm_add_action_or_reset() and manually calls regulator_disable() if adding the action has failed. This leads to double disable and messes the enable count for regulator.

Do not manually call disable if devm_add_action_or_reset() fails.

Fixes 506d2e317a0a ("iio: adc: Add driver support for AD7292")

---

The bug was found during browsing the code. I don't have the hardware to test this so reviewing and testing is highly appreciated.

---
 drivers/iio/adc/ad7292.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/ad7292.c +1 -3
index 92c68d467c50..a2f9fda25ff3 100644
@@ -287,10 +287,8 @@ static int ad7292_probe(struct spi_device *spi)
 
 		ret = devm_add_action_or_reset(&spi->dev,
 					       ad7292_regulator_disable, st);
-		if (ret) {
-			regulator_disable(st->reg);
+		if (ret)
 			return ret;
-		}
 
 		ret = regulator_get_voltage(st->reg);
 		if (ret < 0)
Signature · 14 lines
2.37.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =] 
maintainer
#1 lore raw
Quoted 8 lines · On Fri, 19 Aug 2022 11:51:07 +0300 Matti Vaittinen <[email protected]>…

The ad7292 tries to add an devm_action for disabling a regulator at device detach using devm_add_action_or_reset(). The devm_add_action_or_reset() does call the release function should adding action fail. The driver inspects the value returned by devm_add_action_or_reset() and manually calls regulator_disable() if adding the action has failed. This leads to double disable and messes the enable count for regulator.

Quoted 5 lines

Do not manually call disable if devm_add_action_or_reset() fails.

Fixes 506d2e317a0a ("iio: adc: Add driver support for AD7292")

Good spot. Applied to the fixes-togreg branch of iio.git and marked for stable.

Jonathan

Quoted 24 lines

---

The bug was found during browsing the code. I don't have the hardware to test this so reviewing and testing is highly appreciated.

---
 drivers/iio/adc/ad7292.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/ad7292.c +1 -3
index 92c68d467c50..a2f9fda25ff3 100644
@@ -287,10 +287,8 @@ static int ad7292_probe(struct spi_device *spi)
 
 		ret = devm_add_action_or_reset(&spi->dev,
 					       ad7292_regulator_disable, st);
-		if (ret) {
-			regulator_disable(st->reg);
+		if (ret)
 			return ret;
-		}
 
 		ret = regulator_get_voltage(st->reg);
 		if (ret < 0)
maintainer Tested-by on v1 1/1
#2 lore raw
In reply to Matti Vaittinen

Hi Matti, thank you for this patch.

Quoted 8 lines · Matti Vaittinen

The ad7292 tries to add an devm_action for disabling a regulator at device detach using devm_add_action_or_reset(). The devm_add_action_or_reset() does call the release function should adding action fail. The driver inspects the value returned by devm_add_action_or_reset() and manually calls regulator_disable() if adding the action has failed. This leads to double disable and messes the enable count for regulator.

That's correct. The regulator device even issued a message saying so
fixed-supply: Underflow of regulator enable count

Verified driver behavior on a raspberry pi with eval board.

Thanks again for this fix.

Quoted 4 lines

Do not manually call disable if devm_add_action_or_reset() fails.

Fixes 506d2e317a0a ("iio: adc: Add driver support for AD7292")

Jonathan, can we still add more tags to this patch? If so, please add mine

Quoted 40 lines

---

The bug was found during browsing the code. I don't have the hardware to test this so reviewing and testing is highly appreciated.

---
 drivers/iio/adc/ad7292.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/iio/adc/ad7292.c +1 -3
index 92c68d467c50..a2f9fda25ff3 100644
@@ -287,10 +287,8 @@ static int ad7292_probe(struct spi_device *spi)
 
 		ret = devm_add_action_or_reset(&spi->dev,
 					       ad7292_regulator_disable, st);
-		if (ret) {
-			regulator_disable(st->reg);
+		if (ret)
 			return ret;
-		}
 
 		ret = regulator_get_voltage(st->reg);
 		if (ret < 0)
Signature · 14 lines
2.37.1


-- 
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]