[PATCH v2 03/12] pinctrl: nuvoton: ma35: Retain child firmware node reference in ma35_pinctrl_get_soc_data()

From: Lee Jones

Date: Thu Nov 19 2026 - 15:51:15 EST


for_each_gpiochip_node() drops its reference on each child firmware node
as the loop advances. Storing child directly in bank->fwnode without
acquiring a reference leaves bank->fwnode dangling once the iteration
moves on, leading to a use-after-free when ma35_gpiolib_register()
accesses bank->fwnode.

Acquire a reference on child with fwnode_handle_get() and register a
devres action to release it on probe failure or device teardown.

Fixes: f805e356313b ("pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver")
Closes: https://sashiko.dev/#/bug/linux-f140abe2-145a-4f6b-b626-bbabdc7327c4
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---

v1 => v2: New patch, retaining a reference on bank->fwnode (Sashiko)

drivers/pinctrl/nuvoton/pinctrl-ma35.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index aff2212c6278..c9e09c14a101 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -556,6 +556,11 @@ static int ma35_gpiolib_register(struct platform_device *pdev, struct ma35_pinct
return 0;
}

+static void ma35_bank_fwnode_release(void *data)
+{
+ fwnode_handle_put(data);
+}
+
static void ma35_bank_iounmap(void *data)
{
struct ma35_pin_bank *bank = data;
@@ -629,7 +634,14 @@ static int ma35_pinctrl_get_soc_data(struct ma35_pinctrl *pctl, struct platform_
return -EINVAL;
}
bank = &ctrl->pin_banks[id];
- bank->fwnode = child;
+ bank->fwnode = fwnode_handle_get(child);
+ ret = devm_add_action_or_reset(&pdev->dev,
+ ma35_bank_fwnode_release,
+ bank->fwnode);
+ if (ret) {
+ fwnode_handle_put(child);
+ return ret;
+ }
bank->regmap = pctl->regmap;
bank->dev = &pdev->dev;
ret = ma35_get_bank_data(bank);
--
2.56.1.750.gf70dc682cf-goog