Skip to contentSkip to conversation

pinctrl: imx: scmi: replace custom dt_free_map with pinctrl_utils_free_map

PATCH In review Xiaolei Wang 3 participants 3 messages Oct 26 – Nov 4

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: imx: scmi: replace custom dt_free_map with pinctrl_utils_free_map

From: Wang Xiaolei <[email protected]>

pinctrl_scmi_imx_dt_node_to_map() kmemdup_array()s the pinctrl configs of every pin into map[i].data.configs.configs, but the driver's own pinctrl_scmi_imx_dt_free_map() only frees the map array itself. The pinctrl core releases maps through pinctrl_dt_free_maps(), which calls dt_free_map(); the duplicated configs are therefore never freed and leak every time the DT node is parsed, e.g. on each (deferred) probe attempt.

Replace the custom dt_free_map with the core helper pinctrl_utils_free_map(), which frees the configs of each PIN_MAP_TYPE_CONFIGS_* map before freeing the map itself. Its signature matches pinctrl_ops.dt_free_map(), so the driver-specific implementation can be dropped entirely.

Detected with kmemleak on an i.MX95 board (FRDM-IMX95).

Fixes b755521fd6eb ("pinctrl: imx: support SCMI pinctrl protocol for i.MX95")
---
 drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx-scmi.c +1 -7
index 613552e35070..8cbd66950848 100644
@@ -153,18 +153,12 @@ static int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev,
 	return 0;
 }
 
-static void pinctrl_scmi_imx_dt_free_map(struct pinctrl_dev *pctldev,
-					 struct pinctrl_map *map, unsigned int num_maps)
-{
-	kfree(map);
-}
-
 static const struct pinctrl_ops pinctrl_scmi_imx_pinctrl_ops = {
 	.get_groups_count = pinctrl_generic_get_group_count,
 	.get_group_name = pinctrl_generic_get_group_name,
 	.get_group_pins = pinctrl_generic_get_group_pins,
 	.dt_node_to_map = pinctrl_scmi_imx_dt_node_to_map,
-	.dt_free_map = pinctrl_scmi_imx_dt_free_map,
+	.dt_free_map = pinctrl_utils_free_map,
 };
 
 static int pinctrl_scmi_imx_func_set_mux(struct pinctrl_dev *pctldev,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Xiaolei Wang

[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]

From: Wang Xiaolei <[email protected]>

pinctrl_scmi_imx_dt_node_to_map() kmemdup_array()s the pinctrl configs of every pin into map[i].data.configs.configs, but the driver's own pinctrl_scmi_imx_dt_free_map() only frees the map array itself. The pinctrl core releases maps through pinctrl_dt_free_maps(), which calls dt_free_map(); the duplicated configs are therefore never freed and leak every time the DT node is parsed, e.g. on each (deferred) probe attempt.

Replace the custom dt_free_map with the core helper pinctrl_utils_free_map(), which frees the configs of each PIN_MAP_TYPE_CONFIGS_* map before freeing the map itself. Its signature matches pinctrl_ops.dt_free_map(), so the driver-specific implementation can be dropped entirely.

Quoted 6 lines

Detected with kmemleak on an i.MX95 board (FRDM-IMX95).

Fixes b755521fd6eb ("pinctrl: imx: support SCMI pinctrl protocol for i.MX95")

---

Quoted 31 lines
 drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/pinctrl/freescale/pinctrl-imx-scmi.c +1 -8
index 613552e35070..8cbd66950848 100644
@@ -153,18 +153,12 @@ static int pinctrl_scmi_imx_dt_node_to_map(struct pinctrl_dev *pctldev,
        return 0;
 }
 
-static void pinctrl_scmi_imx_dt_free_map(struct pinctrl_dev *pctldev,
-                                        struct pinctrl_map *map, unsigned int num_maps)
-{
-       kfree(map);
-}
-
 static const struct pinctrl_ops pinctrl_scmi_imx_pinctrl_ops = {
        .get_groups_count = pinctrl_generic_get_group_count,
        .get_group_name = pinctrl_generic_get_group_name,
        .get_group_pins = pinctrl_generic_get_group_pins,
        .dt_node_to_map = pinctrl_scmi_imx_dt_node_to_map,
-       .dt_free_map = pinctrl_scmi_imx_dt_free_map,
+       .dt_free_map = pinctrl_utils_free_map,
 };
 
 static int pinctrl_scmi_imx_func_set_mux(struct pinctrl_dev *pctldev,
--

2.34.1

maintainer
#2 lore raw
In reply to Xiaolei Wang
Quoted 15 lines · Xiaolei Wang

From: Wang Xiaolei <[email protected]>

pinctrl_scmi_imx_dt_node_to_map() kmemdup_array()s the pinctrl configs of every pin into map[i].data.configs.configs, but the driver's own pinctrl_scmi_imx_dt_free_map() only frees the map array itself. The pinctrl core releases maps through pinctrl_dt_free_maps(), which calls dt_free_map(); the duplicated configs are therefore never freed and leak every time the DT node is parsed, e.g. on each (deferred) probe attempt.

Replace the custom dt_free_map with the core helper pinctrl_utils_free_map(), which frees the configs of each PIN_MAP_TYPE_CONFIGS_* map before freeing the map itself. Its signature matches pinctrl_ops.dt_free_map(), so the driver-specific implementation can be dropped entirely.

Quoted 4 lines

Detected with kmemleak on an i.MX95 board (FRDM-IMX95).

Fixes b755521fd6eb ("pinctrl: imx: support SCMI pinctrl protocol for i.MX95")

No way I'm sending that to stable, it's no regression.

Quoted 1 line

Patch applied as a nonurgent fix.

Yours,
Linus Walleij