[PATCH 2/3] pinctrl: single: Don't remove deduplicated groups and functions on error
From: A. Sverdlin
Date: Thu Nov 19 2026 - 18:28:46 EST
From: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
pinctrl_generic_add_group() and pinmux_generic_add_function() return the
selector of an existing entry with the same name instead of adding a new
one. This is the normal case when a node is mapped again, e.g. on
consumer re-probe. If parsing then fails, the error paths of
pcs_parse_one_pinctrl_entry() and pcs_parse_bits_in_pinctrl_entry()
remove the group and function by that selector anyway, i.e. the entries
an earlier mapping is still using.
Besides breaking that mapping, this corrupts the selector space: the
selectors are allocated from num_groups/num_functions, which the removal
decrements, so the last entry is no longer found by name and the next new
entry collides with it in the radix tree (-EEXIST).
Only remove them if this call actually added them, i.e. if the core's
function refers to our pcs_function. As in the success path, testing the
function is enough: the group has the same name and is always added and
removed together with it.
Fixes: a4ab10860723 ("pinctrl: single: Fix group and function selector use")
Signed-off-by: Alexander Sverdlin <alexander.sverdlin@xxxxxxxxxxx>
---
drivers/pinctrl/pinctrl-single.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index 64472465800c4..f5f0b95dc4282 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1116,10 +1116,16 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
return 0;
free_pingroups:
- pinctrl_generic_remove_group(pcs->pctl, gsel);
+ /*
+ * Only remove what we added, not an in-use deduplicated instance. The
+ * group is deduplicated together with the function.
+ */
+ if (pinmux_generic_get_function(pcs->pctl, fsel)->data == function)
+ pinctrl_generic_remove_group(pcs->pctl, gsel);
*num_maps = 1;
free_function:
- pinmux_generic_remove_function(pcs->pctl, fsel);
+ if (pinmux_generic_get_function(pcs->pctl, fsel)->data == function)
+ pinmux_generic_remove_function(pcs->pctl, fsel);
free_pins:
mutex_unlock(&pcs->mutex);
devm_kfree(pcs->dev, pins);
@@ -1262,7 +1268,9 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
return 0;
free_function:
- pinmux_generic_remove_function(pcs->pctl, fsel);
+ /* See pcs_parse_one_pinctrl_entry() */
+ if (pinmux_generic_get_function(pcs->pctl, fsel)->data == function)
+ pinmux_generic_remove_function(pcs->pctl, fsel);
free_pins:
mutex_unlock(&pcs->mutex);
devm_kfree(pcs->dev, pins);
--
2.56.1