Re: [PATCH v2] pinctrl: stm32: Fix reset control leak in stm32_pctl_probe() error paths

From: Antonio Borneo

Date: Thu Nov 19 2026 - 06:27:31 EST


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@xxxxxxxxxxxxxxxxxxxx/
>
> 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@xxxxxxxxxxxxxxxxxxxx/
>
> 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