]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pinctrl: pinconf-generic: Fix memory leak in pinconf_generic_parse_dt_config()
authorFelix Gu <ustc.gu@gmail.com>
Sat, 14 Feb 2026 15:14:51 +0000 (23:14 +0800)
committerLinus Walleij <linusw@kernel.org>
Tue, 24 Feb 2026 09:51:29 +0000 (10:51 +0100)
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@gmail.com>
Reviewed-by: Antonio Borneo <antonio.borneo@foss.st.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
drivers/pinctrl/pinconf-generic.c

index 94b1d057197c60efa56639258f7cf8cd266e2042..2b030bd0e6adca941a40dc4a8da0b5d4a6ebdb22 100644 (file)
@@ -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 */