public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path
@ 2026-05-04 14:53 Felix Gu
  2026-05-04 23:33 ` Andre Przywara
  2026-05-05  9:26 ` Linus Walleij
  0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-05-04 14:53 UTC (permalink / raw)
  To: Linus Walleij, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Maxime Ripard
  Cc: linux-gpio, linux-arm-kernel, linux-sunxi, linux-kernel, Felix Gu

In the error path of sunxi_pmx_request(), the code calls
regulator_put(s_reg->regulator) to release the regulator. However,
s_reg->regulator is only assigned after a successful regulator_enable().
This causes a memory leak: the regulator obtained via regulator_get()
is never properly released when regulator_enable() fails.

Fixes: dc1445584177 ("pinctrl: sunxi: Fix and simplify pin bank regulator handling")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index d3042e0c9712..25489beeb312 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -925,7 +925,7 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
 	return 0;
 
 out:
-	regulator_put(s_reg->regulator);
+	regulator_put(reg);
 
 	return ret;
 }

---
base-commit: b9303e6bff706758c167af686b5315ad00233bf8
change-id: 20260504-sunxi-cda91661c181

Best regards,
-- 
Felix Gu <ustc.gu@gmail.com>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path
  2026-05-04 14:53 [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path Felix Gu
@ 2026-05-04 23:33 ` Andre Przywara
  2026-05-05  9:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Andre Przywara @ 2026-05-04 23:33 UTC (permalink / raw)
  To: Felix Gu
  Cc: Linus Walleij, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
	Maxime Ripard, linux-gpio, linux-arm-kernel, linux-sunxi,
	linux-kernel

On Mon, 04 May 2026 22:53:26 +0800
Felix Gu <ustc.gu@gmail.com> wrote:

> In the error path of sunxi_pmx_request(), the code calls
> regulator_put(s_reg->regulator) to release the regulator. However,
> s_reg->regulator is only assigned after a successful regulator_enable().
> This causes a memory leak: the regulator obtained via regulator_get()
> is never properly released when regulator_enable() fails.

Yes, that's a correct observation. The fix looks alright, though I
wonder if we should drop the "goto" here altogether, since there is only
one caller, and the code would look better like this:

	ret = regulator_enable(reg);
	if (ret) {
		dev_err(pctl->dev, ...
		regulator_put(reg);
		return ret;
        }
...

> Fixes: dc1445584177 ("pinctrl: sunxi: Fix and simplify pin bank regulator handling")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

Regardless, the fix is correct, so:

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>  drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> index d3042e0c9712..25489beeb312 100644
> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> @@ -925,7 +925,7 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
>  	return 0;
>  
>  out:
> -	regulator_put(s_reg->regulator);
> +	regulator_put(reg);
>  
>  	return ret;
>  }
> 
> ---
> base-commit: b9303e6bff706758c167af686b5315ad00233bf8
> change-id: 20260504-sunxi-cda91661c181
> 
> Best regards,


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path
  2026-05-04 14:53 [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path Felix Gu
  2026-05-04 23:33 ` Andre Przywara
@ 2026-05-05  9:26 ` Linus Walleij
  1 sibling, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2026-05-05  9:26 UTC (permalink / raw)
  To: Felix Gu
  Cc: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Maxime Ripard,
	linux-gpio, linux-arm-kernel, linux-sunxi, linux-kernel

On Mon, May 4, 2026 at 4:53 PM Felix Gu <ustc.gu@gmail.com> wrote:

> In the error path of sunxi_pmx_request(), the code calls
> regulator_put(s_reg->regulator) to release the regulator. However,
> s_reg->regulator is only assigned after a successful regulator_enable().
> This causes a memory leak: the regulator obtained via regulator_get()
> is never properly released when regulator_enable() fails.
>
> Fixes: dc1445584177 ("pinctrl: sunxi: Fix and simplify pin bank regulator handling")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

Patch applied as nonurgent fix!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-05  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 14:53 [PATCH] pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path Felix Gu
2026-05-04 23:33 ` Andre Przywara
2026-05-05  9:26 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox