Re: [PATCH] pinctrl: pinconf-generic: Fix memory leak in pinconf_generic_parse_dt_config()
From: Antonio Borneo
Date: Sun Feb 15 2026 - 11:25:02 EST
On Sat, 2026-02-14 at 23:14 +0800, Felix Gu wrote:
> In pinconf_generic_parse_dt_config(), if parse_dt_cfg() fails, it returns
> directly. This bypasses the cleanup logic and results in a memory leak of
> the cfg buffer.
>
> Fix this by jumping to the out label on failure, ensuring kfree(cfg) is
> called before returning.
>
> Fixes: 90a18c512884 ("pinctrl: pinconf-generic: Handle string values for generic properties")
> Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
> ---
> drivers/pinctrl/pinconf-generic.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c
> index 94b1d057197c..2b030bd0e6ad 100644
> --- a/drivers/pinctrl/pinconf-generic.c
> +++ b/drivers/pinctrl/pinconf-generic.c
> @@ -351,13 +351,13 @@ int pinconf_generic_parse_dt_config(struct device_node *np,
>
> ret = parse_dt_cfg(np, dt_params, ARRAY_SIZE(dt_params), cfg, &ncfg);
> if (ret)
> - return ret;
> + goto out;
> if (pctldev && pctldev->desc->num_custom_params &&
> pctldev->desc->custom_params) {
> ret = parse_dt_cfg(np, pctldev->desc->custom_params,
> pctldev->desc->num_custom_params, cfg, &ncfg);
> if (ret)
> - return ret;
> + goto out;
> }
>
> /* no configs found at all */
>
> ---
> base-commit: 635c467cc14ebdffab3f77610217c1dacaf88e8c
> change-id: 20260214-pinconf-cbc1e31088ff
>
> Best regards,
Reviewed-by: Antonio Borneo <antonio.borneo@xxxxxxxxxxx>
Thanks!
Antonio