pinctrl: generic-mux: free maps on pinctrl_generic_to_map() failure
Subsystems (2)
PATCH 1/1 pinctrl: generic-mux: free maps on pinctrl_generic_to_map() failure
From: Surendra Singh Chouhan <[email protected]>
mux_pinmux_dt_node_to_map() calls pinctrl_generic_to_map() to parse DT configuration and allocate pinctrl maps.
If pinctrl_generic_to_map() returns an error, *maps may contain partial map entries allocated by pinctrl_utils_reserve_map(). Returning the error directly without calling pinctrl_utils_free_map() leaks the allocated mapping memory.
Fix this by calling pinctrl_utils_free_map() when pinctrl_generic_to_map() fails.
--- drivers/pinctrl/pinctrl-generic-mux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-generic-mux.c +3 -1
@@ -58,8 +58,10 @@ mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev, num_maps, &num_reserved_maps, group_names, 0, &np_config->name, NULL, 0); -if (ret) +if (ret) { +pinctrl_utils_free_map (pctldev, *maps, *num_maps);return ret; + } ret =pinmux_generic_add_function (pctldev, np_config->name, group_names,1 , function);
Signature · 1 line
2.55.0
Quoted 9 lines · On Thu, Jul 23, 2026 at 12:00:11PM +0530, [email protected] wrote:
From: Surendra Singh Chouhan <[email protected]>
mux_pinmux_dt_node_to_map()callspinctrl_generic_to_map()to parse DT configuration and allocate pinctrl maps.If
pinctrl_generic_to_map()returns an error, *maps may contain partial map entries allocated bypinctrl_utils_reserve_map(). Returning the error directly without callingpinctrl_utils_free_map()leaks the allocated mapping memory.
Fix pinctrl_generic_to_map(), which should cleanup memory before return failure.
Frank
Quoted 29 lines
Fix this by calling
pinctrl_utils_free_map()whenpinctrl_generic_to_map()fails.Fixes 34acc5a8adfb ("pinctrl: add generic board-level pinctrl driver using mux framework")Signed-off-by Surendra Singh Chouhan <[email protected]>--- drivers/pinctrl/pinctrl-generic-mux.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/pinctrl/pinctrl-generic-mux.c +3
-2@@ -58,8 +58,10 @@ mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev, num_maps, &num_reserved_maps, group_names, 0, &np_config->name, NULL, 0); -if (ret) +if (ret) { +pinctrl_utils_free_map (pctldev, *maps, *num_maps);return ret; + } ret =pinmux_generic_add_function (pctldev, np_config->name, group_names,1 , function); --2.55.0