diff mbox series

[v2,2/4] pinctrl: renesas: rzn1: free maps on DT map failure

Message ID 20261003083200.459705-3-yaojiale02@163.com
State New
Headers show
Series pinctrl: free maps on DT mapping failures | expand

Commit Message

Jiale Yao Oct. 3, 2026, 8:31 a.m. UTC
rzn1_dt_node_to_map_one() appends mappings for each DT node.  If a
node fails after map storage has been reserved, the top-level callback
returns without releasing mappings built for the current and previous
nodes.

Free the accumulated map on every error path.  The caller ignores the
output parameters when the mapping callback returns an error, so they do
not need to be reset after freeing the map.

Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/pinctrl/renesas/pinctrl-rzn1.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Linus Walleij Oct. 7, 2026, 10:33 a.m. UTC | #1
On Sat, Oct 3, 2026 at 10:32 AM Jiale Yao <yaojiale02@163.com> wrote:

> rzn1_dt_node_to_map_one() appends mappings for each DT node.  If a
> node fails after map storage has been reserved, the top-level callback
> returns without releasing mappings built for the current and previous
> nodes.
>
> Free the accumulated map on every error path.  The caller ignores the
> output parameters when the mapping callback returns an error, so they do
> not need to be reset after freeing the map.
>
> Signed-off-by: Jiale Yao <yaojiale02@163.com>

Geert will look into this patch and handle it.

Yours,
Linus Walleij
diff mbox series

Patch

diff --git a/drivers/pinctrl/renesas/pinctrl-rzn1.c b/drivers/pinctrl/renesas/pinctrl-rzn1.c
index fb874867dbfb..64a89e307191 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzn1.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzn1.c
@@ -411,15 +411,19 @@  static int rzn1_dt_node_to_map(struct pinctrl_dev *pctldev,
 
 	ret = rzn1_dt_node_to_map_one(pctldev, np, map, num_maps);
 	if (ret < 0)
-		return ret;
+		goto err_free_map;
 
 	for_each_child_of_node_scoped(np, child) {
 		ret = rzn1_dt_node_to_map_one(pctldev, child, map, num_maps);
 		if (ret < 0)
-			return ret;
+			goto err_free_map;
 	}
 
 	return 0;
+
+err_free_map:
+	pinctrl_utils_free_map(pctldev, *map, *num_maps);
+	return ret;
 }
 
 static const struct pinctrl_ops rzn1_pctrl_ops = {