* [PATCH] iio: ad7292: Prevent regulator double disable
@ 2022-08-19 8:51 Matti Vaittinen
2022-08-19 17:12 ` Jonathan Cameron
2022-08-20 20:47 ` Marcelo Schmitt
0 siblings, 2 replies; 3+ messages in thread
From: Matti Vaittinen @ 2022-08-19 8:51 UTC (permalink / raw
To: Matti Vaittinen, Matti Vaittinen
Cc: Marcelo Schmitt, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, linux-iio, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1690 bytes --]
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")
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
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(-)
diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
index 92c68d467c50..a2f9fda25ff3 100644
--- a/drivers/iio/adc/ad7292.c
+++ b/drivers/iio/adc/ad7292.c
@@ -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)
--
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 =]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: ad7292: Prevent regulator double disable
2022-08-19 8:51 [PATCH] iio: ad7292: Prevent regulator double disable Matti Vaittinen
@ 2022-08-19 17:12 ` Jonathan Cameron
2022-08-20 20:47 ` Marcelo Schmitt
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2022-08-19 17:12 UTC (permalink / raw
To: Matti Vaittinen
Cc: Matti Vaittinen, Marcelo Schmitt, Lars-Peter Clausen,
Michael Hennerich, linux-iio, linux-kernel
On Fri, 19 Aug 2022 11:51:07 +0300
Matti Vaittinen <mazziesaccount@gmail.com> wrote:
> 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")
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>
Good spot. Applied to the fixes-togreg branch of iio.git
and marked for stable.
Jonathan
> ---
>
> 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(-)
>
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index 92c68d467c50..a2f9fda25ff3 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio: ad7292: Prevent regulator double disable
2022-08-19 8:51 [PATCH] iio: ad7292: Prevent regulator double disable Matti Vaittinen
2022-08-19 17:12 ` Jonathan Cameron
@ 2022-08-20 20:47 ` Marcelo Schmitt
1 sibling, 0 replies; 3+ messages in thread
From: Marcelo Schmitt @ 2022-08-20 20:47 UTC (permalink / raw
To: Matti Vaittinen
Cc: Matti Vaittinen, Lars-Peter Clausen, Michael Hennerich,
Jonathan Cameron, linux-iio, linux-kernel
Hi Matti, thank you for this patch.
On 08/19, Matti Vaittinen wrote:
> 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.
> Do not manually call disable if devm_add_action_or_reset() fails.
>
> Fixes: 506d2e317a0a ("iio: adc: Add driver support for AD7292")
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Jonathan, can we still add more tags to this patch? If so, please add mine
Tested-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
>
> ---
>
> 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(-)
>
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index 92c68d467c50..a2f9fda25ff3 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -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)
> --
> 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 =]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-20 20:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-19 8:51 [PATCH] iio: ad7292: Prevent regulator double disable Matti Vaittinen
2022-08-19 17:12 ` Jonathan Cameron
2022-08-20 20:47 ` Marcelo Schmitt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).