@@ -259,22 +259,28 @@ static int samsung_dt_node_to_map(struct pinctrl_dev *pctldev,
*map = NULL;
*num_maps = 0;
- if (!of_get_child_count(np_config))
- return samsung_dt_subnode_to_map(drvdata, pctldev->dev,
- np_config, map,
- &reserved_maps,
- num_maps);
+ if (!of_get_child_count(np_config)) {
+ ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev,
+ np_config, map, &reserved_maps,
+ num_maps);
+ if (ret < 0)
+ goto err_free_map;
+
+ return 0;
+ }
for_each_child_of_node_scoped(np_config, np) {
ret = samsung_dt_subnode_to_map(drvdata, pctldev->dev, np, map,
&reserved_maps, num_maps);
- if (ret < 0) {
- samsung_dt_free_map(pctldev, *map, *num_maps);
- return ret;
- }
+ if (ret < 0)
+ goto err_free_map;
}
return 0;
+
+err_free_map:
+ samsung_dt_free_map(pctldev, *map, *num_maps);
+ return ret;
}
#ifdef CONFIG_DEBUG_FS
samsung_dt_subnode_to_map() can reserve map storage before adding configuration entries. The no-child path returns its error directly, and the child path frees mappings on failure. Use one error path that frees the accumulated map in both cases. 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/samsung/pinctrl-samsung.c | 24 ++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)