Re: [PATCH] pinctrl: generic: serialise pinctrl_generic_dt_node_to_map()

From: Linus Walleij

Date: Mon Sep 14 2026 - 05:23:41 EST


On Fri, Aug 28, 2026 at 5:58 PM Sarah Emery <sarah.emery@xxxxxxxxxxxxx> wrote:

> pinctrl_generic_add_group() documents that the caller must take care of
> locking, and pinmux_generic_add_function() needs it too, but
> pinctrl_generic_dt_node_to_map() calls them without holding
> pctldev->mutex, and the core caller in create_pinctrl() does not take it
> either.
>
> The driver core calls pinctrl_bind_pins() before probing a device, so
> two devices that reference the same pin controller can run
> pinctrl_generic_dt_node_to_map() on one pctldev at the same time.
>
> Both `add` functions take the new selector from pctldev->num_groups or
> pctldev->num_functions, and radix_tree_insert() at that index.
> Two racing callers can read the same selector before either
> has inserted, so the second insert collides and fails:
>
> k1-pinctrl d401e000.pinctrl:
> error -EEXIST: error adding function pcie2-0-cfg
> k1-pinctrl d401e000.pinctrl:
> does not have pin group pcie0-0-cfg.pcie0-0-pins
>
> leaving one consumer without its pin configuration.
>
> This was hit on a SpacemiT K3 board, where PCIe devices probe in parallel
> against the single shared pin controller.
>
> Take pctldev->mutex across the whole function, so that the groups and the
> function referring are in a single critical section.
>
> Fixes: 43722575e5cd ("pinctrl: add generic functions + pins mapper")
> Signed-off-by: Sarah Emery <sarah.emery@xxxxxxxxxxxxx>

Patch applied for fixes, sorry for taking so long to respond.

Yours,
Linus Walleij