* [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK
[not found] <cover.1796203691.git.lee@kernel.org>
@ 2026-12-02 9:29 ` Lee Jones
2026-12-02 16:13 ` Antonio Borneo
2026-12-02 9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
` (6 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:29 UTC (permalink / raw)
To: lee, Antonio Borneo, Linus Walleij, Maxime Coquelin,
Alexandre Torgue, Ju Nan, Fabien Dessenne, linux-gpio,
linux-stm32, linux-arm-kernel, linux-kernel
Cc: stable
stm32_gpiolib_register_bank() computes npins from the device tree
"gpio-ranges" property as args.args[0] + args.args[2] without checking
that the resulting value fits within STM32_GPIO_PINS_PER_BANK (16).
Because bank->pin_backup[] is a fixed-size array of
STM32_GPIO_PINS_PER_BANK elements and the hardware registers only have
16 lines per bank, a larger npins value leads to out-of-bounds array
accesses and shift overflows.
Validate that npins is within 1..STM32_GPIO_PINS_PER_BANK.
Fixes: b67210cc217f ("pinctrl: stm32: consider the GPIO offset to expose all the GPIO lines")
Closes: https://sashiko.dev/#/bug/linux-efdf6da1-70b0-4c56-add9-2bc97a4c140d
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index bf16e5814bf8..01c8a646d9a0 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -1657,13 +1657,26 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
bank->gpio_chip.base = args.args[1];
/* get the last defined gpio line (offset + nb of pins) */
+ if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
+ args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
+ fwnode_handle_put(args.fwnode);
+ return -EINVAL;
+ }
npins = args.args[0] + args.args[2];
fwnode_handle_put(args.fwnode);
while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) {
+ if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
+ args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
+ fwnode_handle_put(args.fwnode);
+ return -EINVAL;
+ }
npins = max(npins, (int)(args.args[0] + args.args[2]));
fwnode_handle_put(args.fwnode);
}
+
+ if (!npins)
+ return -EINVAL;
} else {
bank_nr = pctl->nbanks;
bank->gpio_chip.base = bank_nr * STM32_GPIO_PINS_PER_BANK;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio()
[not found] <cover.1796203691.git.lee@kernel.org>
2026-12-02 9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
@ 2026-12-02 9:29 ` Lee Jones
2026-12-02 17:17 ` Frank Li
2026-12-02 9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
` (5 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:29 UTC (permalink / raw)
To: lee, Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Shawn Guo, linux-gpio, imx,
linux-arm-kernel, linux-kernel
Cc: stable
imx_pinctrl_parse_pin_mmio() derives *pin_id from mux_reg / 4 or
conf_reg / 4 and uses it directly to index ipctl->pin_regs[*pin_id] and
info->pins[*pin_id] without bounds checking against info->npins. If a
device tree entry specifies an out-of-range register offset or sets both
mux_reg and conf_reg to 0 on a SoC without ZERO_OFFSET_VALID (making
conf_reg == -1 and *pin_id == 0x3fffffff), this results in an
out-of-bounds memory access.
Validate that *pin_id is less than info->npins and return -EINVAL on
invalid entries.
Fixes: e16415313c9b ("pinctrl: imx: move hard-coding data into device tree")
Closes: https://sashiko.dev/#/bug/linux-b67db85c-1fa1-4c97-9932-88c575b568f2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/freescale/pinctrl-imx.c | 32 ++++++++++++++++++-------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index ebcce9aeac8c..0a825f58448f 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -502,15 +502,16 @@ static const struct pinconf_ops imx_pinconf_ops = {
#define FSL_PIN_SHARE_SIZE 20
#define FSL_SCU_PIN_SIZE 12
-static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
- unsigned int *pin_id, struct imx_pin *pin,
- const __be32 **list_p,
- struct device_node *np)
+static int imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
+ unsigned int *pin_id, struct imx_pin *pin,
+ const __be32 **list_p,
+ struct device_node *np)
{
const struct imx_pinctrl_soc_info *info = ipctl->info;
struct imx_pin_mmio *pin_mmio = &pin->conf.mmio;
struct imx_pin_reg *pin_reg;
const __be32 *list = *list_p;
+ unsigned int id;
u32 mux_reg, conf_reg;
u32 config;
@@ -527,7 +528,14 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
conf_reg = -1;
}
- *pin_id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
+ id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
+ if (id >= info->npins) {
+ dev_err(ipctl->dev, "Invalid pin id %u in node %pOF\n",
+ id, np);
+ return -EINVAL;
+ }
+
+ *pin_id = id;
pin_reg = &ipctl->pin_regs[*pin_id];
pin->pin = *pin_id;
pin_reg->mux_reg = mux_reg;
@@ -547,6 +555,8 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
dev_dbg(ipctl->dev, "%s: 0x%x 0x%08lx", info->pins[*pin_id].name,
pin_mmio->mux_mode, pin_mmio->config);
+
+ return 0;
}
static int imx_pinctrl_parse_groups(struct device_node *np,
@@ -611,10 +621,16 @@ static int imx_pinctrl_parse_groups(struct device_node *np,
for (i = 0; i < grp->grp.npins; i++) {
pin = &((struct imx_pin *)(grp->data))[i];
- if (info->flags & IMX_USE_SCU)
+ if (info->flags & IMX_USE_SCU) {
info->imx_pinctrl_parse_pin(ipctl, &pins[i], pin, &list);
- else
- imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin, &list, np);
+ } else {
+ int ret;
+
+ ret = imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin,
+ &list, np);
+ if (ret)
+ return ret;
+ }
}
return 0;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex
[not found] <cover.1796203691.git.lee@kernel.org>
2026-12-02 9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
2026-12-02 9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
@ 2026-12-02 9:29 ` Lee Jones
2026-12-02 14:08 ` Bartosz Golaszewski
2026-12-02 9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
` (4 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:29 UTC (permalink / raw)
To: lee, Tony Lindgren, Haojian Zhuang, Linus Walleij,
Andy Shevchenko, linux-arm-kernel, linux-omap, linux-gpio,
linux-kernel
Cc: stable
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@vger.kernel.org
Signed-off-by: Lee Jones <lee@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt()
[not found] <cover.1796203691.git.lee@kernel.org>
` (2 preceding siblings ...)
2026-12-02 9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
@ 2026-12-02 9:29 ` Lee Jones
2026-12-02 17:20 ` Frank Li
2026-12-02 9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
` (3 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:29 UTC (permalink / raw)
To: lee, Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Gary Bisson, linux-gpio, imx,
linux-arm-kernel, linux-kernel
Cc: stable
imx_pinctrl_parse_functions() inserts each group descriptor into
pctl->pin_group_tree before calling imx_pinctrl_parse_groups() and
ignores the return value of imx_pinctrl_parse_groups(). Likewise,
imx_pinctrl_probe_dt() ignores the return value of
imx_pinctrl_parse_functions(). If a device tree group node is malformed
or a memory allocation fails, partially initialised group descriptors
with NULL data pointers remain registered in the radix tree and cause a
NULL pointer dereference when the pinctrl core or debugfs accesses the
group.
Parse each group before inserting it into pctl->pin_group_tree and
propagate errors from imx_pinctrl_parse_groups() and
imx_pinctrl_parse_functions(). Return 0 when a function node has no
groups so boards with empty controller nodes continue to probe as
before.
Fixes: e566fc11ea76 ("pinctrl: imx: use generic pinctrl helpers for managing groups")
Closes: https://sashiko.dev/#/bug/linux-70c60bc4-5868-4c94-b1bb-7073f7a3316c
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/freescale/pinctrl-imx.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index 0a825f58448f..b1114dce3485 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -658,7 +658,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
func->ngroups = of_get_child_count(np);
if (func->ngroups == 0) {
dev_info(ipctl->dev, "no groups defined in %pOF\n", np);
- return -EINVAL;
+ return 0;
}
group_names = devm_kzalloc_objs(ipctl->dev, *group_names, func->ngroups);
@@ -679,6 +679,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
if (!grp)
return -ENOMEM;
+ ret = imx_pinctrl_parse_groups(child, grp, ipctl, i++);
+ if (ret)
+ return ret;
+
mutex_lock(&ipctl->mutex);
/*
* FIXME: This should use pinctrl_generic_add_group() and not
@@ -687,8 +691,6 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
radix_tree_insert(&pctl->pin_group_tree,
ipctl->group_index++, grp);
mutex_unlock(&ipctl->mutex);
-
- imx_pinctrl_parse_groups(child, grp, ipctl, i++);
}
return 0;
@@ -718,7 +720,6 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
struct imx_pinctrl *ipctl)
{
struct device_node *np = pdev->dev.of_node;
- struct device_node *child;
struct pinctrl_dev *pctl = ipctl->pctl;
u32 nfuncs = 0;
u32 i = 0;
@@ -743,16 +744,21 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
pctl->num_groups = of_get_child_count(np);
} else {
pctl->num_groups = 0;
- for_each_child_of_node(np, child)
+ for_each_child_of_node_scoped(np, child)
pctl->num_groups += of_get_child_count(child);
}
if (flat_funcs) {
- imx_pinctrl_parse_functions(np, ipctl, 0);
+ return imx_pinctrl_parse_functions(np, ipctl, 0);
} else {
+ int ret;
+
i = 0;
- for_each_child_of_node(np, child)
- imx_pinctrl_parse_functions(child, ipctl, i++);
+ for_each_child_of_node_scoped(np, child) {
+ ret = imx_pinctrl_parse_functions(child, ipctl, i++);
+ if (ret)
+ return ret;
+ }
}
return 0;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock
[not found] <cover.1796203691.git.lee@kernel.org>
` (3 preceding siblings ...)
2026-12-02 9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
@ 2026-12-02 9:30 ` Lee Jones
2026-12-02 17:22 ` Frank Li
2026-12-02 9:30 ` [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs Lee Jones
` (2 subsequent siblings)
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:30 UTC (permalink / raw)
To: lee, Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Bartosz Golaszewski, Haibo Chen,
Takashi Sakamoto, Danilo Krummrich, Bjorn Helgaas,
Uwe Kleine-König (The Capable Hub), Shawn Guo, linux-gpio,
imx, linux-arm-kernel, linux-kernel
Cc: stable
The pinctrl core does not serialise .set_mux() and .pin_config_set()
callbacks against one another or against concurrent .set_mux() calls.
On i.MX platforms that share mux and configuration registers via
SHARE_MUX_CONF_REG or share general-purpose select-input registers,
concurrent read-modify-write sequences in imx_pmx_set_one_pin_mmio(),
imx_pinconf_set_mmio(), and the GPIO direction callbacks can race and
overwrite each other's updates.
Add a raw_spinlock_t to struct imx_pinctrl and hold it across MMIO
read-modify-write register updates.
Fixes: 94176faf279b ("pinctrl: imx: work around select input quirk")
Closes: https://sashiko.dev/#/bug/linux-ccaf34b8-b920-49e6-a8b2-363ee2e9785b
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/freescale/pinctrl-imx.c | 10 ++++++++++
drivers/pinctrl/freescale/pinctrl-imx.h | 2 ++
drivers/pinctrl/freescale/pinctrl-imx7ulp.c | 3 +++
drivers/pinctrl/freescale/pinctrl-imx8ulp.c | 3 +++
drivers/pinctrl/freescale/pinctrl-vf610.c | 3 +++
5 files changed, 21 insertions(+)
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index b1114dce3485..807f72b8b6ab 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -168,6 +168,7 @@ static int imx_pmx_set_one_pin_mmio(struct imx_pinctrl *ipctl,
const struct imx_pinctrl_soc_info *info = ipctl->info;
struct imx_pin_mmio *pin_mmio = &pin->conf.mmio;
const struct imx_pin_reg *pin_reg;
+ unsigned long flags;
unsigned int pin_id;
pin_id = pin->pin;
@@ -182,10 +183,12 @@ static int imx_pmx_set_one_pin_mmio(struct imx_pinctrl *ipctl,
if (info->flags & SHARE_MUX_CONF_REG) {
u32 reg;
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
reg = readl(ipctl->base + pin_reg->mux_reg);
reg &= ~info->mux_mask;
reg |= (pin_mmio->mux_mode << info->mux_shift);
writel(reg, ipctl->base + pin_reg->mux_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%x\n",
pin_reg->mux_reg, reg);
} else {
@@ -217,10 +220,12 @@ static int imx_pmx_set_one_pin_mmio(struct imx_pinctrl *ipctl,
* The input_reg[i] here is actually some IOMUXC general
* purpose register, not regular select input register.
*/
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
val = readl(ipctl->base + pin_mmio->input_reg);
val &= ~mask;
val |= select << shift;
writel(val, ipctl->base + pin_mmio->input_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
} else if (pin_mmio->input_reg) {
/*
* Regular select input register can never be at offset
@@ -390,11 +395,15 @@ static int imx_pinconf_set_mmio(struct pinctrl_dev *pctldev,
for (i = 0; i < num_configs; i++) {
if (info->flags & SHARE_MUX_CONF_REG) {
+ unsigned long flags;
u32 reg;
+
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
reg = readl(ipctl->base + pin_reg->conf_reg);
reg &= info->mux_mask;
reg |= configs[i];
writel(reg, ipctl->base + pin_reg->conf_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
dev_dbg(ipctl->dev, "write: offset 0x%x val 0x%x\n",
pin_reg->conf_reg, reg);
} else {
@@ -840,6 +849,7 @@ int imx_pinctrl_probe(struct platform_device *pdev,
imx_pmx_ops.gpio_set_direction = info->gpio_set_direction;
mutex_init(&ipctl->mutex);
+ raw_spin_lock_init(&ipctl->lock);
ipctl->info = info;
ipctl->dev = &pdev->dev;
diff --git a/drivers/pinctrl/freescale/pinctrl-imx.h b/drivers/pinctrl/freescale/pinctrl-imx.h
index 8fa7e1e2521d..0d33584fa710 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.h
+++ b/drivers/pinctrl/freescale/pinctrl-imx.h
@@ -12,6 +12,7 @@
#define __DRIVERS_PINCTRL_IMX_H
#include <linux/pinctrl/pinmux.h>
+#include <linux/spinlock.h>
struct platform_device;
@@ -79,6 +80,7 @@ struct imx_pinctrl {
struct imx_pin_reg *pin_regs;
unsigned int group_index;
struct mutex mutex;
+ raw_spinlock_t lock;
};
struct imx_pinctrl_soc_info {
diff --git a/drivers/pinctrl/freescale/pinctrl-imx7ulp.c b/drivers/pinctrl/freescale/pinctrl-imx7ulp.c
index 063805daee03..b44bbc77ab4a 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx7ulp.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx7ulp.c
@@ -263,18 +263,21 @@ static int imx7ulp_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
{
struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
const struct imx_pin_reg *pin_reg;
+ unsigned long flags;
u32 reg;
pin_reg = &ipctl->pin_regs[offset];
if (pin_reg->mux_reg == -1)
return -EINVAL;
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
reg = readl(ipctl->base + pin_reg->mux_reg);
if (input)
reg = (reg & ~BM_OBE_ENABLED) | BM_IBE_ENABLED;
else
reg = (reg & ~BM_IBE_ENABLED) | BM_OBE_ENABLED;
writel(reg, ipctl->base + pin_reg->mux_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
return 0;
}
diff --git a/drivers/pinctrl/freescale/pinctrl-imx8ulp.c b/drivers/pinctrl/freescale/pinctrl-imx8ulp.c
index 88af25b0d48e..a869de92aeba 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx8ulp.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx8ulp.c
@@ -222,18 +222,21 @@ static int imx8ulp_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
{
struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
const struct imx_pin_reg *pin_reg;
+ unsigned long flags;
u32 reg;
pin_reg = &ipctl->pin_regs[offset];
if (pin_reg->mux_reg == -1)
return -EINVAL;
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
reg = readl(ipctl->base + pin_reg->mux_reg);
if (input)
reg = (reg & ~BM_OBE_ENABLED) | BM_IBE_ENABLED;
else
reg = (reg & ~BM_IBE_ENABLED) | BM_OBE_ENABLED;
writel(reg, ipctl->base + pin_reg->mux_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
return 0;
}
diff --git a/drivers/pinctrl/freescale/pinctrl-vf610.c b/drivers/pinctrl/freescale/pinctrl-vf610.c
index 77d077618782..930e414ca8d7 100644
--- a/drivers/pinctrl/freescale/pinctrl-vf610.c
+++ b/drivers/pinctrl/freescale/pinctrl-vf610.c
@@ -295,6 +295,7 @@ static int vf610_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
{
struct imx_pinctrl *ipctl = pinctrl_dev_get_drvdata(pctldev);
const struct imx_pin_reg *pin_reg;
+ unsigned long flags;
u32 reg;
pin_reg = &ipctl->pin_regs[offset];
@@ -302,12 +303,14 @@ static int vf610_pmx_gpio_set_direction(struct pinctrl_dev *pctldev,
return -EINVAL;
/* IBE always enabled allows us to read the value "on the wire" */
+ raw_spin_lock_irqsave(&ipctl->lock, flags);
reg = readl(ipctl->base + pin_reg->mux_reg);
if (input)
reg &= ~0x2;
else
reg |= 0x2;
writel(reg, ipctl->base + pin_reg->mux_reg);
+ raw_spin_unlock_irqrestore(&ipctl->lock, flags);
return 0;
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs
[not found] <cover.1796203691.git.lee@kernel.org>
` (4 preceding siblings ...)
2026-12-02 9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
@ 2026-12-02 9:30 ` Lee Jones
2026-12-02 9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
2026-12-02 9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
7 siblings, 0 replies; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:30 UTC (permalink / raw)
To: lee, Jacky Huang, Shan-Chun Hung, Linus Walleij, linux-arm-kernel,
linux-gpio, linux-kernel
Cc: stable
ma35_pinctrl_parse_groups() allocates a single configs array via
pinconf_generic_parse_dt_config() and assigns the same pointer to every
pin in the group. ma35_pinctrl_dt_node_to_map_func() then copies that
shared pointer into every PIN_MAP_TYPE_CONFIGS_PIN map entry. Because
ma35_pctrl_ops uses pinconf_generic_dt_free_map(), tearing down the
pinctrl mapping frees the same configs pointer once per pin, causing an
immediate double free and leaving dangling pointers in the group data
for subsequent mappings. The configs array is also leaked on error
paths in ma35_pinctrl_parse_groups().
Manage the lifetime of the shared configs array with a devm action
registered right after pinconf_generic_parse_dt_config(), and use a
dedicated dt_free_map callback that frees only the map array.
Fixes: f805e356313b ("pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver")
Closes: https://sashiko.dev/#/bug/linux-ec1cf664-4937-4cb3-831c-e2c7838a1aae
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index c20350bc1cdb..b9b34b8b84c6 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -17,6 +17,7 @@
#include <linux/platform_device.h>
#include <linux/property.h>
#include <linux/regmap.h>
+#include <linux/slab.h>
#include <linux/pinctrl/pinconf.h>
#include <linux/pinctrl/pinctrl.h>
@@ -236,12 +237,18 @@ static int ma35_pinctrl_dt_node_to_map_func(struct pinctrl_dev *pctldev,
return 0;
}
+static void ma35_dt_free_map(struct pinctrl_dev *pctldev,
+ struct pinctrl_map *map, unsigned int num_maps)
+{
+ kfree(map);
+}
+
static const struct pinctrl_ops ma35_pctrl_ops = {
.get_groups_count = ma35_get_groups_count,
.get_group_name = ma35_get_group_name,
.get_group_pins = ma35_get_group_pins,
.dt_node_to_map = ma35_pinctrl_dt_node_to_map_func,
- .dt_free_map = pinconf_generic_dt_free_map,
+ .dt_free_map = ma35_dt_free_map,
};
static int ma35_pinmux_get_func_count(struct pinctrl_dev *pctldev)
@@ -1028,6 +1035,11 @@ static const struct pinconf_ops ma35_pinconf_ops = {
.is_generic = true,
};
+static void ma35_free_configs(void *data)
+{
+ kfree(data);
+}
+
static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_desc *grp,
struct ma35_pinctrl *npctl, u32 index)
{
@@ -1043,6 +1055,13 @@ static int ma35_pinctrl_parse_groups(struct fwnode_handle *fwnode, struct group_
if (ret)
return ret;
+ if (configs) {
+ ret = devm_add_action_or_reset(npctl->dev, ma35_free_configs,
+ configs);
+ if (ret)
+ return ret;
+ }
+
count = fwnode_property_count_u32(fwnode, "nuvoton,pins");
if (!count || count % 3)
return -EINVAL;
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free
[not found] <cover.1796203691.git.lee@kernel.org>
` (5 preceding siblings ...)
2026-12-02 9:30 ` [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs Lee Jones
@ 2026-12-02 9:30 ` Lee Jones
2026-12-02 9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
7 siblings, 0 replies; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:30 UTC (permalink / raw)
To: lee, Linus Walleij, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
Andre Przywara, Maxime Ripard, linux-gpio, linux-arm-kernel,
linux-sunxi, linux-kernel
Cc: stable
The pinmux core invokes pmxops->request() and pmxops->free() without
holding a controller-wide lock. When two pins in the same 32-pin bank
are requested or freed concurrently, sunxi_pmx_request() and
sunxi_pmx_free() race on s_reg->regulator and s_reg->refcount, which can
result in duplicate regulator_get()/regulator_enable() calls or
addition-on-zero refcount warnings.
Serialise per-bank regulator acquisition and release in
sunxi_pmx_request() and sunxi_pmx_free() with a mutex.
Fixes: 9a2a566adb00 ("pinctrl: sunxi: Deal with per-bank regulators")
Closes: https://sashiko.dev/#/bug/linux-8e59d9d1-607f-4eba-a596-fa524b707d0e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 17 ++++++++++-------
drivers/pinctrl/sunxi/pinctrl-sunxi.h | 3 +++
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index bf4ec4665e2b..d20415b885a9 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -10,6 +10,7 @@
* warranty of any kind, whether express or implied.
*/
+#include <linux/cleanup.h>
#include <linux/clk.h>
#include <linux/export.h>
#include <linux/gpio/driver.h>
@@ -913,13 +914,16 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
unsigned short bank_offset = bank - pctl->desc->pin_base /
PINS_PER_BANK;
struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset];
- struct regulator *reg = s_reg->regulator;
+ struct regulator *reg;
char supply[16];
int ret;
if (WARN_ON_ONCE(bank_offset >= ARRAY_SIZE(pctl->regulators)))
return -EINVAL;
+ guard(mutex)(&pctl->reg_lock);
+
+ reg = s_reg->regulator;
if (reg) {
refcount_inc(&s_reg->refcount);
return 0;
@@ -936,7 +940,8 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
if (ret) {
dev_err(pctl->dev,
"Couldn't enable bank P%c regulator\n", 'A' + bank);
- goto out;
+ regulator_put(reg);
+ return ret;
}
sunxi_pinctrl_set_io_bias_cfg(pctl, offset, reg);
@@ -945,11 +950,6 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
refcount_set(&s_reg->refcount, 1);
return 0;
-
-out:
- regulator_put(reg);
-
- return ret;
}
static int sunxi_pmx_free(struct pinctrl_dev *pctldev, unsigned offset)
@@ -960,6 +960,8 @@ static int sunxi_pmx_free(struct pinctrl_dev *pctldev, unsigned offset)
PINS_PER_BANK;
struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset];
+ guard(mutex)(&pctl->reg_lock);
+
if (!refcount_dec_and_test(&s_reg->refcount))
return 0;
@@ -1609,6 +1611,7 @@ int sunxi_pinctrl_init_with_flags(struct platform_device *pdev,
platform_set_drvdata(pdev, pctl);
raw_spin_lock_init(&pctl->lock);
+ mutex_init(&pctl->reg_lock);
pctl->membase = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(pctl->membase))
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.h b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
index 7c2f29e75519..1d8547e9492e 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.h
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
@@ -14,6 +14,7 @@
#define __PINCTRL_SUNXI_H
#include <linux/kernel.h>
+#include <linux/mutex.h>
#include <linux/spinlock.h>
#define PA_BASE 0
@@ -187,6 +188,8 @@ struct sunxi_pinctrl {
int *irq;
unsigned *irq_array;
raw_spinlock_t lock;
+ /* Protects @regulators */
+ struct mutex reg_lock;
/*
* Output latch shadow, one word per bank. Seeded lockless at
* probe before the pinctrl device registers, protected by @lock
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume
[not found] <cover.1796203691.git.lee@kernel.org>
` (6 preceding siblings ...)
2026-12-02 9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
@ 2026-12-02 9:30 ` Lee Jones
2026-12-02 15:28 ` Antonio Borneo
7 siblings, 1 reply; 14+ messages in thread
From: Lee Jones @ 2026-12-02 9:30 UTC (permalink / raw)
To: lee, Antonio Borneo, Linus Walleij, Maxime Coquelin,
Alexandre Torgue, Ju Nan, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel
Cc: stable
Four IRQ lines share each 32-bit EXTI mux register in SYSCFG, and on
heterogeneous multi-core SoCs (such as STM32MP1) those registers are
shared with a remote coprocessor. While stm32_gpio_domain_alloc()
serialises regmap_field_write(pctl->irqmux[...]) with both
pctl->irqmux_lock and pctl->hwlock, stm32_pinctrl_restore_gpio_regs()
updates pctl->irqmux[offset] during resume without acquiring either
lock, risking a read-modify-write race with the coprocessor.
Acquire pctl->irqmux_lock and pctl->hwlock around the irqmux register
restore in stm32_pinctrl_restore_gpio_regs().
Fixes: e2f3cf18c3e2 ("pinctrl: stm32: add suspend/resume management")
Closes: https://sashiko.dev/#/bug/linux-f428a25e-342d-4e81-bdba-0948cff6c22d
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 01c8a646d9a0..897da5fafaf4 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -2094,9 +2094,27 @@ static int __maybe_unused stm32_pinctrl_restore_gpio_regs(
return ret;
}
- if (pin_is_irq)
+ if (pin_is_irq) {
+ unsigned long flags;
+
+ spin_lock_irqsave(&pctl->irqmux_lock, flags);
+ if (pctl->hwlock) {
+ ret = hwspin_lock_timeout_in_atomic(pctl->hwlock,
+ HWSPNLCK_TIMEOUT_MS);
+ if (ret) {
+ dev_err(pctl->dev, "Can't get hwspinlock\n");
+ spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
+ return ret;
+ }
+ }
+
regmap_field_write(pctl->irqmux[offset], bank->bank_ioport_nr);
+ if (pctl->hwlock)
+ hwspin_unlock_in_atomic(pctl->hwlock);
+ spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
+ }
+
return 0;
}
--
2.56.1.911.g883d8bcb20-goog
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex
2026-12-02 9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
@ 2026-12-02 14:08 ` Bartosz Golaszewski
0 siblings, 0 replies; 14+ messages in thread
From: Bartosz Golaszewski @ 2026-12-02 14:08 UTC (permalink / raw)
To: Lee Jones
Cc: Tony Lindgren, Haojian Zhuang, Linus Walleij, Andy Shevchenko,
linux-arm-kernel, linux-omap, linux-gpio, linux-kernel, stable
On Wed, Dec 02, 2026 at 09:29:57AM +0000, Lee Jones wrote:
> 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@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume
2026-12-02 9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
@ 2026-12-02 15:28 ` Antonio Borneo
0 siblings, 0 replies; 14+ messages in thread
From: Antonio Borneo @ 2026-12-02 15:28 UTC (permalink / raw)
To: Lee Jones, Linus Walleij, Maxime Coquelin, Alexandre Torgue,
Ju Nan, linux-gpio, linux-stm32, linux-arm-kernel, linux-kernel
Cc: stable
On Wed, 2026-12-02 at 09:30 +0000, Lee Jones wrote:
> Four IRQ lines share each 32-bit EXTI mux register in SYSCFG, and on
> heterogeneous multi-core SoCs (such as STM32MP1) those registers are
> shared with a remote coprocessor. While stm32_gpio_domain_alloc()
> serialises regmap_field_write(pctl->irqmux[...]) with both
> pctl->irqmux_lock and pctl->hwlock, stm32_pinctrl_restore_gpio_regs()
> updates pctl->irqmux[offset] during resume without acquiring either
> lock, risking a read-modify-write race with the coprocessor.
>
> Acquire pctl->irqmux_lock and pctl->hwlock around the irqmux register
> restore in stm32_pinctrl_restore_gpio_regs().
>
> Fixes: e2f3cf18c3e2 ("pinctrl: stm32: add suspend/resume management")
> Closes: https://sashiko.dev/#/bug/linux-f428a25e-342d-4e81-bdba-0948cff6c22d
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/pinctrl/stm32/pinctrl-stm32.c | 20 +++++++++++++++++++-
> 1 file changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index 01c8a646d9a0..897da5fafaf4 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -2094,9 +2094,27 @@ static int __maybe_unused stm32_pinctrl_restore_gpio_regs(
> return ret;
> }
>
> - if (pin_is_irq)
> + if (pin_is_irq) {
> + unsigned long flags;
> +
> + spin_lock_irqsave(&pctl->irqmux_lock, flags);
> + if (pctl->hwlock) {
> + ret = hwspin_lock_timeout_in_atomic(pctl->hwlock,
> + HWSPNLCK_TIMEOUT_MS);
> + if (ret) {
> + dev_err(pctl->dev, "Can't get hwspinlock\n");
> + spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
> + return ret;
> + }
> + }
> +
> regmap_field_write(pctl->irqmux[offset], bank->bank_ioport_nr);
>
> + if (pctl->hwlock)
> + hwspin_unlock_in_atomic(pctl->hwlock);
> + spin_unlock_irqrestore(&pctl->irqmux_lock, flags);
> + }
> +
> return 0;
> }
>
Reviewed-by: Antonio Borneo <antonio.borneo@foss.st.com>
Thanks,
Antonio
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK
2026-12-02 9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
@ 2026-12-02 16:13 ` Antonio Borneo
0 siblings, 0 replies; 14+ messages in thread
From: Antonio Borneo @ 2026-12-02 16:13 UTC (permalink / raw)
To: Lee Jones, Linus Walleij, Maxime Coquelin, Alexandre Torgue,
Ju Nan, Fabien Dessenne, linux-gpio, linux-stm32,
linux-arm-kernel, linux-kernel
Cc: stable
On Wed, 2026-12-02 at 09:29 +0000, Lee Jones wrote:
> stm32_gpiolib_register_bank() computes npins from the device tree
> "gpio-ranges" property as args.args[0] + args.args[2] without checking
> that the resulting value fits within STM32_GPIO_PINS_PER_BANK (16).
> Because bank->pin_backup[] is a fixed-size array of
> STM32_GPIO_PINS_PER_BANK elements and the hardware registers only have
> 16 lines per bank, a larger npins value leads to out-of-bounds array
> accesses and shift overflows.
>
> Validate that npins is within 1..STM32_GPIO_PINS_PER_BANK.
>
> Fixes: b67210cc217f ("pinctrl: stm32: consider the GPIO offset to expose all the GPIO lines")
> Closes: https://sashiko.dev/#/bug/linux-efdf6da1-70b0-4c56-add9-2bc97a4c140d
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/pinctrl/stm32/pinctrl-stm32.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
> index bf16e5814bf8..01c8a646d9a0 100644
> --- a/drivers/pinctrl/stm32/pinctrl-stm32.c
> +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
> @@ -1657,13 +1657,26 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
> bank->gpio_chip.base = args.args[1];
>
> /* get the last defined gpio line (offset + nb of pins) */
> + if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
> + args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
> + fwnode_handle_put(args.fwnode);
> + return -EINVAL;
> + }
> npins = args.args[0] + args.args[2];
> fwnode_handle_put(args.fwnode);
>
> while (!fwnode_property_get_reference_args(fwnode, "gpio-ranges", NULL, 3, ++i, &args)) {
> + if (args.args[0] >= STM32_GPIO_PINS_PER_BANK ||
> + args.args[2] > STM32_GPIO_PINS_PER_BANK - args.args[0]) {
> + fwnode_handle_put(args.fwnode);
> + return -EINVAL;
> + }
> npins = max(npins, (int)(args.args[0] + args.args[2]));
> fwnode_handle_put(args.fwnode);
> }
> +
> + if (!npins)
> + return -EINVAL;
> } else {
> bank_nr = pctl->nbanks;
> bank->gpio_chip.base = bank_nr * STM32_GPIO_PINS_PER_BANK;
Hi Lee,
I agree, this change fixes the case of incorrect values for the DT property
"gpio-ranges", values not checked by 'make dtbs_check'.
I thought we should trust the DT as correct, avoiding too many checks in the drivers.
Is there any news I have missed?
Or is this a special case, as it involves a potential out-of-bounds array access?
Anyway,
Reviewed-by: Antonio Borneo <antonio.borneo@foss.st.com>
Thanks,
Antonio
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio()
2026-12-02 9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
@ 2026-12-02 17:17 ` Frank Li
0 siblings, 0 replies; 14+ messages in thread
From: Frank Li @ 2026-12-02 17:17 UTC (permalink / raw)
To: Lee Jones
Cc: Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Shawn Guo, linux-gpio, imx,
linux-arm-kernel, linux-kernel, stable
On Wed, Dec 02, 2026 at 09:29:56AM +0000, Lee Jones wrote:
> imx_pinctrl_parse_pin_mmio() derives *pin_id from mux_reg / 4 or
> conf_reg / 4 and uses it directly to index ipctl->pin_regs[*pin_id] and
> info->pins[*pin_id] without bounds checking against info->npins. If a
> device tree entry specifies an out-of-range register offset or sets both
> mux_reg and conf_reg to 0 on a SoC without ZERO_OFFSET_VALID (making
> conf_reg == -1 and *pin_id == 0x3fffffff), this results in an
> out-of-bounds memory access.
>
> Validate that *pin_id is less than info->npins and return -EINVAL on
> invalid entries.
>
> Fixes: e16415313c9b ("pinctrl: imx: move hard-coding data into device tree")
> Closes: https://sashiko.dev/#/bug/linux-b67db85c-1fa1-4c97-9932-88c575b568f2
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> drivers/pinctrl/freescale/pinctrl-imx.c | 32 ++++++++++++++++++-------
> 1 file changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
> index ebcce9aeac8c..0a825f58448f 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx.c
> @@ -502,15 +502,16 @@ static const struct pinconf_ops imx_pinconf_ops = {
> #define FSL_PIN_SHARE_SIZE 20
> #define FSL_SCU_PIN_SIZE 12
>
> -static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
> - unsigned int *pin_id, struct imx_pin *pin,
> - const __be32 **list_p,
> - struct device_node *np)
> +static int imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
> + unsigned int *pin_id, struct imx_pin *pin,
> + const __be32 **list_p,
> + struct device_node *np)
> {
> const struct imx_pinctrl_soc_info *info = ipctl->info;
> struct imx_pin_mmio *pin_mmio = &pin->conf.mmio;
> struct imx_pin_reg *pin_reg;
> const __be32 *list = *list_p;
> + unsigned int id;
> u32 mux_reg, conf_reg;
> u32 config;
>
> @@ -527,7 +528,14 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
> conf_reg = -1;
> }
>
> - *pin_id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
> + id = (mux_reg != -1) ? mux_reg / 4 : conf_reg / 4;
> + if (id >= info->npins) {
> + dev_err(ipctl->dev, "Invalid pin id %u in node %pOF\n",
> + id, np);
> + return -EINVAL;
> + }
> +
> + *pin_id = id;
> pin_reg = &ipctl->pin_regs[*pin_id];
> pin->pin = *pin_id;
> pin_reg->mux_reg = mux_reg;
> @@ -547,6 +555,8 @@ static void imx_pinctrl_parse_pin_mmio(struct imx_pinctrl *ipctl,
>
> dev_dbg(ipctl->dev, "%s: 0x%x 0x%08lx", info->pins[*pin_id].name,
> pin_mmio->mux_mode, pin_mmio->config);
> +
> + return 0;
> }
>
> static int imx_pinctrl_parse_groups(struct device_node *np,
> @@ -611,10 +621,16 @@ static int imx_pinctrl_parse_groups(struct device_node *np,
>
> for (i = 0; i < grp->grp.npins; i++) {
> pin = &((struct imx_pin *)(grp->data))[i];
> - if (info->flags & IMX_USE_SCU)
> + if (info->flags & IMX_USE_SCU) {
> info->imx_pinctrl_parse_pin(ipctl, &pins[i], pin, &list);
> - else
> - imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin, &list, np);
> + } else {
> + int ret;
> +
> + ret = imx_pinctrl_parse_pin_mmio(ipctl, &pins[i], pin,
> + &list, np);
> + if (ret)
> + return ret;
> + }
> }
>
> return 0;
> --
> 2.56.1.911.g883d8bcb20-goog
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt()
2026-12-02 9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
@ 2026-12-02 17:20 ` Frank Li
0 siblings, 0 replies; 14+ messages in thread
From: Frank Li @ 2026-12-02 17:20 UTC (permalink / raw)
To: Lee Jones
Cc: Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Gary Bisson, linux-gpio, imx,
linux-arm-kernel, linux-kernel, stable
On Wed, Dec 02, 2026 at 09:29:58AM +0000, Lee Jones wrote:
> imx_pinctrl_parse_functions() inserts each group descriptor into
> pctl->pin_group_tree before calling imx_pinctrl_parse_groups() and
> ignores the return value of imx_pinctrl_parse_groups(). Likewise,
> imx_pinctrl_probe_dt() ignores the return value of
> imx_pinctrl_parse_functions(). If a device tree group node is malformed
> or a memory allocation fails, partially initialised group descriptors
> with NULL data pointers remain registered in the radix tree and cause a
> NULL pointer dereference when the pinctrl core or debugfs accesses the
> group.
>
> Parse each group before inserting it into pctl->pin_group_tree and
> propagate errors from imx_pinctrl_parse_groups() and
> imx_pinctrl_parse_functions(). Return 0 when a function node has no
> groups so boards with empty controller nodes continue to probe as
> before.
>
> Fixes: e566fc11ea76 ("pinctrl: imx: use generic pinctrl helpers for managing groups")
> Closes: https://sashiko.dev/#/bug/linux-70c60bc4-5868-4c94-b1bb-7073f7a3316c
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
> drivers/pinctrl/freescale/pinctrl-imx.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
> index 0a825f58448f..b1114dce3485 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx.c
> @@ -658,7 +658,7 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
> func->ngroups = of_get_child_count(np);
> if (func->ngroups == 0) {
> dev_info(ipctl->dev, "no groups defined in %pOF\n", np);
> - return -EINVAL;
> + return 0;
I think it is correct to allow empty groups, but need seperate patch for
it.
> }
>
> group_names = devm_kzalloc_objs(ipctl->dev, *group_names, func->ngroups);
> @@ -679,6 +679,10 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
> if (!grp)
> return -ENOMEM;
>
> + ret = imx_pinctrl_parse_groups(child, grp, ipctl, i++);
> + if (ret)
> + return ret;
> +
> mutex_lock(&ipctl->mutex);
> /*
> * FIXME: This should use pinctrl_generic_add_group() and not
> @@ -687,8 +691,6 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
> radix_tree_insert(&pctl->pin_group_tree,
> ipctl->group_index++, grp);
> mutex_unlock(&ipctl->mutex);
> -
> - imx_pinctrl_parse_groups(child, grp, ipctl, i++);
> }
>
> return 0;
> @@ -718,7 +720,6 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
> struct imx_pinctrl *ipctl)
> {
> struct device_node *np = pdev->dev.of_node;
> - struct device_node *child;
> struct pinctrl_dev *pctl = ipctl->pctl;
> u32 nfuncs = 0;
> u32 i = 0;
> @@ -743,16 +744,21 @@ static int imx_pinctrl_probe_dt(struct platform_device *pdev,
> pctl->num_groups = of_get_child_count(np);
> } else {
> pctl->num_groups = 0;
> - for_each_child_of_node(np, child)
> + for_each_child_of_node_scoped(np, child)
This one fix difference problem, need seperate patch to fix it
Frank
> pctl->num_groups += of_get_child_count(child);
> }
>
> if (flat_funcs) {
> - imx_pinctrl_parse_functions(np, ipctl, 0);
> + return imx_pinctrl_parse_functions(np, ipctl, 0);
> } else {
> + int ret;
> +
> i = 0;
> - for_each_child_of_node(np, child)
> - imx_pinctrl_parse_functions(child, ipctl, i++);
> + for_each_child_of_node_scoped(np, child) {
> + ret = imx_pinctrl_parse_functions(child, ipctl, i++);
> + if (ret)
> + return ret;
> + }
> }
>
> return 0;
> --
> 2.56.1.911.g883d8bcb20-goog
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock
2026-12-02 9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
@ 2026-12-02 17:22 ` Frank Li
0 siblings, 0 replies; 14+ messages in thread
From: Frank Li @ 2026-12-02 17:22 UTC (permalink / raw)
To: Lee Jones
Cc: Dong Aisheng, Fabio Estevam, Frank Li, Jacky Bai,
Pengutronix Kernel Team, NXP S32 Linux Team, Linus Walleij,
Sascha Hauer, Mehmet Fide, Bartosz Golaszewski, Haibo Chen,
Takashi Sakamoto, Danilo Krummrich, Bjorn Helgaas,
Uwe Kleine-König (The Capable Hub), Shawn Guo, linux-gpio,
imx, linux-arm-kernel, linux-kernel, stable
On Wed, Dec 02, 2026 at 09:30:00AM +0000, Lee Jones wrote:
> The pinctrl core does not serialise .set_mux() and .pin_config_set()
> callbacks against one another or against concurrent .set_mux() calls.
> On i.MX platforms that share mux and configuration registers via
> SHARE_MUX_CONF_REG or share general-purpose select-input registers,
> concurrent read-modify-write sequences in imx_pmx_set_one_pin_mmio(),
> imx_pinconf_set_mmio(), and the GPIO direction callbacks can race and
> overwrite each other's updates.
>
> Add a raw_spinlock_t to struct imx_pinctrl and hold it across MMIO
why choose raw_spinlock_t instead of spinlock_t?
Frank
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-12-02 17:34 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1796203691.git.lee@kernel.org>
2026-12-02 9:29 ` [PATCH 01/12] pinctrl: stm32: Validate npins against STM32_GPIO_PINS_PER_BANK Lee Jones
2026-12-02 16:13 ` Antonio Borneo
2026-12-02 9:29 ` [PATCH 02/12] pinctrl: imx: Validate pin_id in imx_pinctrl_parse_pin_mmio() Lee Jones
2026-12-02 17:17 ` Frank Li
2026-12-02 9:29 ` [PATCH 03/12] pinctrl: single: Protect group and function updates with pctldev->mutex Lee Jones
2026-12-02 14:08 ` Bartosz Golaszewski
2026-12-02 9:29 ` [PATCH 04/12] pinctrl: imx: Propagate DT parsing errors in imx_pinctrl_probe_dt() Lee Jones
2026-12-02 17:20 ` Frank Li
2026-12-02 9:30 ` [PATCH 06/12] pinctrl: imx: Serialise MMIO register updates with a spinlock Lee Jones
2026-12-02 17:22 ` Frank Li
2026-12-02 9:30 ` [PATCH 07/12] pinctrl: nuvoton: ma35: Avoid double free of shared pin configs Lee Jones
2026-12-02 9:30 ` [PATCH 10/12] pinctrl: sunxi: Serialise per-bank regulator request and free Lee Jones
2026-12-02 9:30 ` [PATCH 11/12] pinctrl: stm32: Protect irqmux restore with hwspinlock during resume Lee Jones
2026-12-02 15:28 ` Antonio Borneo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox