Skip to contentSkip to conversation

pinctrl: pinconf-generic: Fix memory leak in pinconf_generic_parse_dt_config()

PATCH In review Felix Gu 3 participants 3 messages Feb 14 – Feb 24

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 pinctrl: pinconf-generic: Fix memory leak in pinconf_generic_parse_dt_config()

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")
---
 drivers/pinctrl/pinconf-generic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinconf-generic.c +2 -2
index 94b1d057197c..2b030bd0e6ad 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 34 lines · Felix Gu

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")

---
 drivers/pinctrl/pinconf-generic.c | 4 ++--

 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinconf-generic.c +0 -0
index 94b1d057197c..2b030bd0e6ad 100644
@@ -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 */

Quoted 5 lines

---
base-commit: 635c467cc14ebdffab3f77610217c1dacaf88e8c
change-id: 20260214-pinconf-cbc1e31088ff

Best regards,

Thanks!
Antonio

maintainer
#2 lore raw
In reply to Felix Gu
Quoted 9 lines · Felix Gu

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")

Patch applied for fixes.

Yours,
Linus Walleij