Re: [PATCH] pinctrl: imx: scmi: replace custom dt_free_map with pinctrl_utils_free_map
From: Frank Li
Date: Mon Oct 26 2026 - 12:53:46 EST
On Mon, Oct 26, 2026 at 12:02:30PM +0800, Xiaolei Wang wrote:
> [You don't often get email from xiaoleiwangxiaolei@xxxxxxxxx. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> From: Wang Xiaolei <xiaoleiwangxiaolei@xxxxxxxxx>
>
> 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")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Wang Xiaolei <xiaoleiwangxiaolei@xxxxxxxxx>
> ---
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
> drivers/pinctrl/freescale/pinctrl-imx-scmi.c | 8 +-------
> 1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
> index 613552e35070..8cbd66950848 100644
> --- a/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
> +++ b/drivers/pinctrl/freescale/pinctrl-imx-scmi.c
> @@ -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
>
>