Skip to contentSkip to conversation

pinctrl: spacemit: fix double free of map

PATCH In review Dan Carpenter 3 participants 3 messages Oct 23, 2024 – Oct 28, 2024

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

PATCH 1/1 pinctrl: spacemit: fix double free of map

The map pointer is freed by pinctrl_utils_free_map(). It must not be a devm_ pointer or it leads to a double free when the device is unloaded.

This is similar to a couple bugs Harshit Mogalapalli fixed earlier in commits 3fd976afe974 ("pinctrl: nuvoton: fix a double free in ma35_pinctrl_dt_node_to_map_func()") and 4575962aeed6 ("pinctrl: sophgo:
fix double free in cv1800_pctrl_dt_node_to_map()").

Fixes a83c29e1d145 ("pinctrl: spacemit: add support for SpacemiT K1 SoC")
---
 drivers/pinctrl/spacemit/pinctrl-k1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +1 -1
index c75ea27b2344..a32579d73613 100644
@@ -314,7 +314,7 @@ static int spacemit_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	if (!grpnames)
 		return -ENOMEM;
 
-	map = devm_kcalloc(dev, ngroups * 2, sizeof(*map), GFP_KERNEL);
+	map = kcalloc(ngroups * 2, sizeof(*map), GFP_KERNEL);
 	if (!map)
 		return -ENOMEM;
 
Signature · 1 line
2.45.2
Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dan Carpenter

The map pointer is freed by pinctrl_utils_free_map(). It must not be a devm_ pointer or it leads to a double free when the device is unloaded.

This is similar to a couple bugs Harshit Mogalapalli fixed earlier in commits 3fd976afe974 ("pinctrl: nuvoton: fix a double free in ma35_pinctrl_dt_node_to_map_func()") and 4575962aeed6 ("pinctrl: sophgo:
fix double free in cv1800_pctrl_dt_node_to_map()").

Fixes a83c29e1d145 ("pinctrl: spacemit: add support for SpacemiT K1 SoC")

thanks,

Quoted 19 lines
---
 drivers/pinctrl/spacemit/pinctrl-k1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/spacemit/pinctrl-k1.c +1 -1
index c75ea27b2344..a32579d73613 100644
@@ -314,7 +314,7 @@ static int spacemit_pctrl_dt_node_to_map(struct pinctrl_dev *pctldev,
 	if (!grpnames)
 		return -ENOMEM;
 
-	map = devm_kcalloc(dev, ngroups * 2, sizeof(*map), GFP_KERNEL);
+	map = kcalloc(ngroups * 2, sizeof(*map), GFP_KERNEL);
 	if (!map)
 		return -ENOMEM;
 
Signature · 1 line
2.45.2
Signature · 3 lines
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
#2 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

The map pointer is freed by pinctrl_utils_free_map(). It must not be a devm_ pointer or it leads to a double free when the device is unloaded.

This is similar to a couple bugs Harshit Mogalapalli fixed earlier in commits 3fd976afe974 ("pinctrl: nuvoton: fix a double free in ma35_pinctrl_dt_node_to_map_func()") and 4575962aeed6 ("pinctrl: sophgo:
fix double free in cv1800_pctrl_dt_node_to_map()").

Fixes a83c29e1d145 ("pinctrl: spacemit: add support for SpacemiT K1 SoC")

Patch applied!

Yours,
Linus Walleij