* [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
@ 2026-11-10 8:32 Xiangwu Lai
2026-11-18 21:08 ` Linus Walleij
2026-11-18 21:09 ` Linus Walleij
0 siblings, 2 replies; 5+ messages in thread
From: Xiangwu Lai @ 2026-11-10 8:32 UTC (permalink / raw)
To: antonio.borneo, linusw
Cc: mcoquelin.stm32, alexandre.torgue, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel, Xiangwu Lai
stm32_pctl_probe() acquires an exclusive reset control for every GPIO
bank with of_reset_control_get_exclusive(), but none of the error
paths release them again: the bank loop returns directly on
-EPROBE_DEFER and on a failed clock lookup, and the
clk_bulk_prepare_enable() failure and the err_register path also
leave the already acquired reset controls behind.
On success the reset controls are kept for the lifetime of the device
and are never released either (the driver has no .remove), but that
is harmless. On a failed probe, and in particular when the probe is
retried after -EPROBE_DEFER, every attempt leaks another set of
reset control references.
Release the acquired reset controls on all error paths.
Also release the clocks of the already processed banks on the
-EPROBE_DEFER path, which was missed by the earlier clock leak fix
dfd8259507c5 ("pinctrl: stm32: Fix clock reference leak in
stm32_pctl_probe()").
Fixes: 2254e77665d5 ("pinctrl: stm32: defer probe if reset resource is not yet ready")
Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
---
Changes in v2:
- Point the Fixes tag at 2254e77665d5, which introduced the reset
control acquisition in the stm32_pctl_probe() bank loop and the
-EPROBE_DEFER return path; bb949ed9b16b only replaced the child
node iteration helper (suggested by Sashiko AI review).
- Also release the clocks of the already processed banks on the
-EPROBE_DEFER path, which was missed by dfd8259507c5.
Link: https://lore.kernel.org/all/20261110065722.1340-1-laixiangwu@cmss.chinamobile.com
drivers/pinctrl/stm32/pinctrl-stm32.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 98cf9c6f4..2a54a0176 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1966,15 +1966,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
bank->rstc = of_reset_control_get_exclusive(np, NULL);
if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) {
fwnode_handle_put(child);
- return -EPROBE_DEFER;
+ clk_bulk_put(i, pctl->clks);
+ ret = -EPROBE_DEFER;
+ goto err_put_rstcs;
}
pctl->clks[i].clk = of_clk_get_by_name(np, NULL);
if (IS_ERR(pctl->clks[i].clk)) {
fwnode_handle_put(child);
clk_bulk_put(i, pctl->clks);
- return dev_err_probe(dev, PTR_ERR(pctl->clks[i].clk),
- "failed to get clk\n");
+ ret = dev_err_probe(dev, PTR_ERR(pctl->clks[i].clk),
+ "failed to get clk\n");
+ goto err_put_rstcs;
}
pctl->clks[i].id = "pctl";
i++;
@@ -1984,7 +1987,7 @@ int stm32_pctl_probe(struct platform_device *pdev)
if (ret) {
dev_err(dev, "failed to prepare_enable clk (%d)\n", ret);
clk_bulk_put(banks, pctl->clks);
- return ret;
+ goto err_put_rstcs;
}
for_each_gpiochip_node(dev, child) {
@@ -2009,6 +2012,10 @@ int stm32_pctl_probe(struct platform_device *pdev)
clk_bulk_disable_unprepare(banks, pctl->clks);
clk_bulk_put(banks, pctl->clks);
+err_put_rstcs:
+ for (i = 0; i < banks; i++)
+ if (!IS_ERR_OR_NULL(pctl->banks[i].rstc))
+ reset_control_put(pctl->banks[i].rstc);
return ret;
}
EXPORT_SYMBOL(stm32_pctl_probe);
--
2.50.1.windows.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
2026-11-10 8:32 [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths Xiangwu Lai
@ 2026-11-18 21:08 ` Linus Walleij
2026-11-18 21:09 ` Linus Walleij
1 sibling, 0 replies; 5+ messages in thread
From: Linus Walleij @ 2026-11-18 21:08 UTC (permalink / raw)
To: Xiangwu Lai, Philipp Zabel
Cc: antonio.borneo, mcoquelin.stm32, alexandre.torgue, linux-gpio,
linux-stm32, linux-arm-kernel, linux-kernel
On Tue, Nov 10, 2026 at 9:32 AM Xiangwu Lai
<laixiangwu@cmss.chinamobile.com> wrote:
> stm32_pctl_probe() acquires an exclusive reset control for every GPIO
> bank with of_reset_control_get_exclusive(), but none of the error
> paths release them again: the bank loop returns directly on
> -EPROBE_DEFER and on a failed clock lookup, and the
> clk_bulk_prepare_enable() failure and the err_register path also
> leave the already acquired reset controls behind.
>
> On success the reset controls are kept for the lifetime of the device
> and are never released either (the driver has no .remove), but that
> is harmless. On a failed probe, and in particular when the probe is
> retried after -EPROBE_DEFER, every attempt leaks another set of
> reset control references.
>
> Release the acquired reset controls on all error paths.
>
> Also release the clocks of the already processed banks on the
> -EPROBE_DEFER path, which was missed by the earlier clock leak fix
> dfd8259507c5 ("pinctrl: stm32: Fix clock reference leak in
> stm32_pctl_probe()").
>
> Fixes: 2254e77665d5 ("pinctrl: stm32: defer probe if reset resource is not yet ready")
> Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
> ---
> Changes in v2:
>
> - Point the Fixes tag at 2254e77665d5, which introduced the reset
> control acquisition in the stm32_pctl_probe() bank loop and the
> -EPROBE_DEFER return path; bb949ed9b16b only replaced the child
> node iteration helper (suggested by Sashiko AI review).
> - Also release the clocks of the already processed banks on the
> -EPROBE_DEFER path, which was missed by dfd8259507c5.
>
> Link: https://lore.kernel.org/all/20261110065722.1340-1-laixiangwu@cmss.chinamobile.com
> drivers/pinctrl/stm32/pinctrl-stm32.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index 98cf9c6f4..2a54a0176 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -1966,15 +1966,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
> bank->rstc = of_reset_control_get_exclusive(np, NULL);
> if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) {
> fwnode_handle_put(child);
> - return -EPROBE_DEFER;
> + clk_bulk_put(i, pctl->clks);
> + ret = -EPROBE_DEFER;
> + goto err_put_rstcs;
Looks like a bulky fix, what about just stop using
of_reset_control_get_exclusive()
and use devm_reset_control_get_exclusive(&pdev->dev, ..) hmm?
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
2026-11-10 8:32 [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths Xiangwu Lai
2026-11-18 21:08 ` Linus Walleij
@ 2026-11-18 21:09 ` Linus Walleij
2026-11-19 6:09 ` Xiangwu Lai
1 sibling, 1 reply; 5+ messages in thread
From: Linus Walleij @ 2026-11-18 21:09 UTC (permalink / raw)
To: Xiangwu Lai
Cc: antonio.borneo, mcoquelin.stm32, alexandre.torgue, linux-gpio,
linux-stm32, linux-arm-kernel, linux-kernel
On Tue, Nov 10, 2026 at 9:32 AM Xiangwu Lai
<laixiangwu@cmss.chinamobile.com> wrote:
> Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
Fix your email address in .gitconfig please so you don't use
your login name as name.
Example:
[user]
name = Linus Walleij
email = linusw@kernel.org
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
2026-11-18 21:09 ` Linus Walleij
@ 2026-11-19 6:09 ` Xiangwu Lai
2026-11-19 11:27 ` Antonio Borneo
0 siblings, 1 reply; 5+ messages in thread
From: Xiangwu Lai @ 2026-11-19 6:09 UTC (permalink / raw)
To: Linus Walleij
Cc: Xiangwu Lai, Philipp Zabel, Antonio Borneo, Maxime Coquelin,
Alexandre Torgue, linux-gpio, linux-stm32, linux-arm-kernel,
linux-kernel
Hi Linus,
thanks for taking a look. For the record, this is about "[PATCH v2]
pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error
paths":
https://lore.kernel.org/all/20261110083253.1525-1-laixiangwu@cmss.chinamobile.com/
On Wed, Nov 18, 2026 at 10:09:40PM +0100, Linus Walleij wrote:
> Fix your email address in .gitconfig please so you don't use
> your login name as name.
Sorry about that. The email address is unchanged, what was wrong is
that git picked my login handle up as the user name; the .gitconfig
name is set to "Xiangwu Lai" now, and the patch was already resent
with the corrected author and sign-off before your reply arrived - it
is identical to v2 otherwise:
[PATCH v3] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
https://lore.kernel.org/all/20261116031043.502-1-laixiangwu@cmss.chinamobile.com/
On Wed, Nov 18, 2026 at 10:08:09PM +0100, Linus Walleij wrote:
> Looks like a bulky fix, what about just stop using
> of_reset_control_get_exclusive()
> and use devm_reset_control_get_exclusive(&pdev->dev, ..) hmm?
The managed getter is unfortunately not a drop-in replacement here:
the reset phandles live in the per-bank child nodes, while
devm_reset_control_get_exclusive() resolves the "resets" property
from dev_fwnode(&pdev->dev), that is the pinctrl node itself. The
driver fetches one reset line per GPIO bank from each child:
bank->rstc = of_reset_control_get_exclusive(np, NULL);
with np = to_of_node(child). The reset core only provides devm
variants that take a struct device *; there is no devm getter
parameterized by a device_node/fwnode, which is what the per-bank
lookup would need.
If you prefer the managed form, the equivalent that keeps the
child-node lookup would be to register the put as a devm action after
each successful get:
static void stm32_pctl_put_reset_control(void *data)
{
reset_control_put(data);
}
bank->rstc = of_reset_control_get_exclusive(np, NULL);
if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) {
...
return -EPROBE_DEFER;
}
ret = devm_add_action_or_reset(dev, stm32_pctl_put_reset_control,
bank->rstc);
which turns all the error paths back into plain returns - devres
releases the rstcs acquired so far - and removes the goto
err_put_rstcs wiring from v3. On success the semantics stay as they
are: the rstcs are held for the lifetime of the device (the driver
has no .remove) and are still in use, stm32_gpiolib_register_bank()
deasserts them. phy-qcom-qmp-pcie-msm8996.c uses the same
combination for the same reason, a reset phandle living in a
sub-node.
Philipp, does this look sane from the reset core point of view, or
would a devm getter that takes a fwnode be something acceptable in
the core?
I can respin a v4 with the devm action conversion on top of v3, or
keep the explicit unwind of v3 - let me know which form you prefer.
Best regards,
Xiangwu Lai
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
2026-11-19 6:09 ` Xiangwu Lai
@ 2026-11-19 11:27 ` Antonio Borneo
0 siblings, 0 replies; 5+ messages in thread
From: Antonio Borneo @ 2026-11-19 11:27 UTC (permalink / raw)
To: Xiangwu Lai, Linus Walleij, Krzysztof Kozlowski
Cc: Philipp Zabel, Maxime Coquelin, Alexandre Torgue, linux-gpio,
linux-stm32, linux-arm-kernel, linux-kernel
On Thu, 2026-11-19 at 14:09 +0800, Xiangwu Lai wrote:
> Hi Linus,
>
> thanks for taking a look. For the record, this is about "[PATCH v2]
> pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error
> paths":
>
> https://lore.kernel.org/all/20261110083253.1525-1-laixiangwu@cmss.chinamobile.com/
>
> On Wed, Nov 18, 2026 at 10:09:40PM +0100, Linus Walleij wrote:
> > Fix your email address in .gitconfig please so you don't use
> > your login name as name.
>
> Sorry about that. The email address is unchanged, what was wrong is
> that git picked my login handle up as the user name; the .gitconfig
> name is set to "Xiangwu Lai" now, and the patch was already resent
> with the corrected author and sign-off before your reply arrived - it
> is identical to v2 otherwise:
>
> [PATCH v3] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
> https://lore.kernel.org/all/20261116031043.502-1-laixiangwu@cmss.chinamobile.com/
>
> On Wed, Nov 18, 2026 at 10:08:09PM +0100, Linus Walleij wrote:
> > Looks like a bulky fix, what about just stop using
> > of_reset_control_get_exclusive()
> > and use devm_reset_control_get_exclusive(&pdev->dev, ..) hmm?
>
> The managed getter is unfortunately not a drop-in replacement here:
> the reset phandles live in the per-bank child nodes, while
> devm_reset_control_get_exclusive() resolves the "resets" property
> from dev_fwnode(&pdev->dev), that is the pinctrl node itself. The
> driver fetches one reset line per GPIO bank from each child:
>
> bank->rstc = of_reset_control_get_exclusive(np, NULL);
>
> with np = to_of_node(child). The reset core only provides devm
> variants that take a struct device *; there is no devm getter
> parameterized by a device_node/fwnode, which is what the per-bank
> lookup would need.
>
> If you prefer the managed form, the equivalent that keeps the
> child-node lookup would be to register the put as a devm action after
> each successful get:
>
> static void stm32_pctl_put_reset_control(void *data)
> {
> reset_control_put(data);
> }
>
> bank->rstc = of_reset_control_get_exclusive(np, NULL);
> if (PTR_ERR(bank->rstc) == -EPROBE_DEFER) {
> ...
> return -EPROBE_DEFER;
> }
>
> ret = devm_add_action_or_reset(dev, stm32_pctl_put_reset_control,
> bank->rstc);
>
> which turns all the error paths back into plain returns - devres
> releases the rstcs acquired so far - and removes the goto
> err_put_rstcs wiring from v3. On success the semantics stay as they
> are: the rstcs are held for the lifetime of the device (the driver
> has no .remove) and are still in use, stm32_gpiolib_register_bank()
> deasserts them. phy-qcom-qmp-pcie-msm8996.c uses the same
> combination for the same reason, a reset phandle living in a
> sub-node.
>
> Philipp, does this look sane from the reset core point of view, or
> would a devm getter that takes a fwnode be something acceptable in
> the core?
>
> I can respin a v4 with the devm action conversion on top of v3, or
> keep the explicit unwind of v3 - let me know which form you prefer.
The driver's "resets" property is not currently used by any upstream DT.
Using it is also problematic, as asserting the reset affects all GPIOs in
the bank, including those already configured by the bootloader or secure
world. The current driver uses this only to deassert the reset during
probe.
As part of the cleanup following the planned removal of armv7m support,
I was considering removing this unused property from both the binding and
the driver. Although the ST reference manual documents a per-bank reset,
I lean toward removing its support given the maintenance burden of unused
code.
I've added Krzysztof in copy to get his early feedback on whether removing
the "resets" property from the binding would be acceptable and appropriate.
This patch has the "Fixes:" tag. Whatever the evolution of this thread,
I think this patch should be taken for backport in stable then,
eventually, followed by the "resets" removal.
Regards,
Antonio
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-19 11:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-10 8:32 [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths Xiangwu Lai
2026-11-18 21:08 ` Linus Walleij
2026-11-18 21:09 ` Linus Walleij
2026-11-19 6:09 ` Xiangwu Lai
2026-11-19 11:27 ` Antonio Borneo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®