Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths
From: Linus Walleij
Date: Wed Nov 18 2026 - 16:08:33 EST
On Tue, Nov 10, 2026 at 9:32 AM Xiangwu Lai
<laixiangwu@xxxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxx>
> ---
> 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@xxxxxxxxxxxxxxxxxxxx
> 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