[PATCH] mfd: stmpe: Fix a corner case in stmpe_probe()

Christophe JAILLET posted 1 patch 2 years, 7 months ago
drivers/mfd/stmpe.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] mfd: stmpe: Fix a corner case in stmpe_probe()
Posted by Christophe JAILLET 2 years, 7 months ago
In stmpe_probe(), if some regulator_enable() calls fail, probing continues
and there is only a dev_warn().

So, if stmpe_probe() is called the regulator may not be enabled. It is
cleaner to test it before calling regulator_disable() in the remove
function.

Fixes: 9c9e321455fb ("mfd: stmpe: add optional regulators")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/mfd/stmpe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index a92301dfc712..9c3cf58457a7 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1485,9 +1485,9 @@ int stmpe_probe(struct stmpe_client_info *ci, enum stmpe_partnum partnum)
 
 void stmpe_remove(struct stmpe *stmpe)
 {
-	if (!IS_ERR(stmpe->vio))
+	if (!IS_ERR(stmpe->vio) && regulator_is_enabled(stmpe->vio))
 		regulator_disable(stmpe->vio);
-	if (!IS_ERR(stmpe->vcc))
+	if (!IS_ERR(stmpe->vcc) && regulator_is_enabled(stmpe->vcc))
 		regulator_disable(stmpe->vcc);
 
 	__stmpe_disable(stmpe, STMPE_BLOCK_ADC);
-- 
2.34.1
Re: [PATCH] mfd: stmpe: Fix a corner case in stmpe_probe()
Posted by Lee Jones 2 years, 7 months ago
On Sat, 17 Jun 2023, Christophe JAILLET wrote:

> In stmpe_probe(), if some regulator_enable() calls fail, probing continues
> and there is only a dev_warn().
> 
> So, if stmpe_probe() is called the regulator may not be enabled. It is
> cleaner to test it before calling regulator_disable() in the remove
> function.
> 
> Fixes: 9c9e321455fb ("mfd: stmpe: add optional regulators")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/mfd/stmpe.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Applied, thanks

-- 
Lee Jones [李琼斯]
Re: [PATCH] mfd: stmpe: Fix a corner case in stmpe_probe()
Posted by Linus Walleij 2 years, 7 months ago
On Sat, Jun 17, 2023 at 12:43 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:

> In stmpe_probe(), if some regulator_enable() calls fail, probing continues
> and there is only a dev_warn().
>
> So, if stmpe_probe() is called the regulator may not be enabled. It is
> cleaner to test it before calling regulator_disable() in the remove
> function.
>
> Fixes: 9c9e321455fb ("mfd: stmpe: add optional regulators")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Looks correct!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij