[PATCH v2 05/12] pinctrl: nuvoton: ma35: Avoid leaking map when parent node is missing
From: Lee Jones
Date: Thu Nov 19 2026 - 15:51:11 EST
Commit 3fd976afe974 ("pinctrl: nuvoton: fix a double free in
ma35_pinctrl_dt_node_to_map_func()") switched new_map from
devm_kcalloc() to unmanaged kcalloc() without freeing new_map on the
!parent error path. Because pinctrl_dt_to_map() does not invoke
dt_free_map() when dt_node_to_map() returns an error, new_map is leaked
if of_get_parent() returns NULL.
Look up the parent node before allocating new_map, and release the
parent node reference if the allocation fails.
Fixes: 3fd976afe974 ("pinctrl: nuvoton: fix a double free in ma35_pinctrl_dt_node_to_map_func()")
Closes: https://sashiko.dev/#/bug/linux-ae0c2737-0408-4808-9bae-f7389beb51d0
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v1 => v2:
- Correct description of commit 3fd976afe974 in commit message
(Sashiko)
drivers/pinctrl/nuvoton/pinctrl-ma35.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/pinctrl/nuvoton/pinctrl-ma35.c b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
index a92945b7821f..92c1c40339f1 100644
--- a/drivers/pinctrl/nuvoton/pinctrl-ma35.c
+++ b/drivers/pinctrl/nuvoton/pinctrl-ma35.c
@@ -202,17 +202,19 @@ static int ma35_pinctrl_dt_node_to_map_func(struct pinctrl_dev *pctldev,
return -EINVAL;
}
+ parent = of_get_parent(np);
+ if (!parent)
+ return -EINVAL;
+
map_num += grp->grp.npins;
new_map = kzalloc_objs(*new_map, map_num);
- if (!new_map)
+ if (!new_map) {
+ of_node_put(parent);
return -ENOMEM;
+ }
*map = new_map;
*num_maps = map_num;
- /* create mux map */
- parent = of_get_parent(np);
- if (!parent)
- return -EINVAL;
setting = grp->data;
--
2.56.1.750.gf70dc682cf-goog