[PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex

Lee Jones lee at kernel.org
Wed Dec 2 01:29:57 PST 2026


pcs_parse_one_pinctrl_entry() and pcs_parse_bits_in_pinctrl_entry()
mutate pcs->pctl->pin_function_tree and pcs->pctl->pin_group_tree via
pcs_add_function(), pinctrl_generic_add_group(), and their removal
helpers while holding only the driver-private pcs->mutex.  However, the
pinctrl core debugfs readers and teardown paths traverse and modify
those radix trees under pctldev->mutex, leaving concurrent readers and
writers racing without a shared lock.

Acquire pcs->pctl->mutex instead of pcs->mutex in both parsing
functions so all generic group and function tree operations are
serialised against the pinctrl core.

Fixes: a4ab10860723 ("pinctrl: single: Fix group and function selector use")
Closes: https://sashiko.dev/#/bug/linux-e32b7426-4575-4354-a2fe-409cde3480ce
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/pinctrl/pinctrl-single.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
index e351cdf50669..618f8fc6ee6c 100644
--- a/drivers/pinctrl/pinctrl-single.c
+++ b/drivers/pinctrl/pinctrl-single.c
@@ -1059,7 +1059,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
 	}
 
 	pgnames[0] = np->name;
-	mutex_lock(&pcs->mutex);
+	mutex_lock(&pcs->pctl->mutex);
 	fsel = pcs_add_function(pcs, &function, np->name, vals, found,
 				pgnames, 1);
 	if (fsel < 0) {
@@ -1102,7 +1102,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
 		devm_kfree(pcs->dev, function);
 		devm_kfree(pcs->dev, pgnames);
 	}
-	mutex_unlock(&pcs->mutex);
+	mutex_unlock(&pcs->pctl->mutex);
 
 	return 0;
 
@@ -1118,7 +1118,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
 	if (pinmux_generic_get_function(pcs->pctl, fsel)->data == function)
 		pinmux_generic_remove_function(pcs->pctl, fsel);
 free_pins:
-	mutex_unlock(&pcs->mutex);
+	mutex_unlock(&pcs->pctl->mutex);
 	devm_kfree(pcs->dev, pins);
 
 free_vals:
@@ -1229,7 +1229,7 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
 	}
 
 	pgnames[0] = np->name;
-	mutex_lock(&pcs->mutex);
+	mutex_lock(&pcs->pctl->mutex);
 	fsel = pcs_add_function(pcs, &function, np->name, vals, found,
 				pgnames, 1);
 	if (fsel < 0) {
@@ -1254,7 +1254,7 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
 		devm_kfree(pcs->dev, function);
 		devm_kfree(pcs->dev, pgnames);
 	}
-	mutex_unlock(&pcs->mutex);
+	mutex_unlock(&pcs->pctl->mutex);
 
 	return 0;
 
@@ -1263,7 +1263,7 @@ static int pcs_parse_bits_in_pinctrl_entry(struct pcs_device *pcs,
 	if (pinmux_generic_get_function(pcs->pctl, fsel)->data == function)
 		pinmux_generic_remove_function(pcs->pctl, fsel);
 free_pins:
-	mutex_unlock(&pcs->mutex);
+	mutex_unlock(&pcs->pctl->mutex);
 	devm_kfree(pcs->dev, pins);
 
 free_vals:
-- 
2.56.1.911.g883d8bcb20-goog




More information about the linux-arm-kernel mailing list