Skip to contentSkip to conversation

pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path

PATCH In review Felix Gu 3 participants 3 messages May 4 – May 5

Subsystems (3)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 pinctrl: sunxi: fix regulator leak in sunxi_pmx_request() error path

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")
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/sunxi/pinctrl-sunxi.c +1 -1
index d3042e0c9712..25489beeb312 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Mon, 04 May 2026 22:53:26 +0800 Felix Gu <[email protected]> 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;
        }

...

Quoted 2 lines
Fixes dc1445584177 ("pinctrl: sunxi: Fix and simplify pin bank regulator handling")

Regardless, the fix is correct, so:

Cheers,
Andre

Quoted 23 lines
---
 drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/sunxi/pinctrl-sunxi.c +1 -2
index d3042e0c9712..25489beeb312 100644
@@ -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,

maintainer
#2 lore raw
In reply to Felix Gu
Quoted 8 lines · 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")

Patch applied as nonurgent fix!

Yours,
Linus Walleij