Skip to contentSkip to conversation

mfd: syscon: Fix leak of syscon name

PATCH In review Ansuel Smith 2 participants 2 messages May 25, 2021

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

PATCH 1/1 mfd: syscon: Fix leak of syscon name

regmap_init_mmio duplicate the name and never free the provided name in the sysconf_config. Always free the name instead of freeing only on error to fix error from kmemleak generated by any syscon user.

---
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mfd/syscon.c +1 -1
index c6f139b2e0c0..765c0210cb52 100644
@@ -108,6 +108,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 	syscon_config.max_register = resource_size(&res) - reg_io_width;
 
 	regmap = regmap_init_mmio(NULL, base, &syscon_config);
+	kfree(syscon_config.name);
 	if (IS_ERR(regmap)) {
 		pr_err("regmap init failed\n");
 		ret = PTR_ERR(regmap);
@@ -144,7 +145,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 	regmap_exit(regmap);
 err_regmap:
 	iounmap(base);
-	kfree(syscon_config.name);
 err_map:
 	kfree(syscon);
 	return ERR_PTR(ret);
Signature · 1 line
2.31.1
#1 lore raw
Quoted 8 lines · Ansuel Smith

regmap_init_mmio duplicate the name and never free the provided name in the sysconf_config. Always free the name instead of freeing only on error to fix error from kmemleak generated by any syscon user.

---
 drivers/mfd/syscon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Which repo have you authored this against?

I believe this is already fixed in -next.

Quoted 20 lines
drivers/mfd/syscon.c +1 -1
index c6f139b2e0c0..765c0210cb52 100644
@@ -108,6 +108,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 	syscon_config.max_register = resource_size(&res) - reg_io_width;
 
 	regmap = regmap_init_mmio(NULL, base, &syscon_config);
+	kfree(syscon_config.name);
 	if (IS_ERR(regmap)) {
 		pr_err("regmap init failed\n");
 		ret = PTR_ERR(regmap);
@@ -144,7 +145,6 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_clk)
 	regmap_exit(regmap);
 err_regmap:
 	iounmap(base);
-	kfree(syscon_config.name);
 err_map:
 	kfree(syscon);
 	return ERR_PTR(ret);
Signature · 4 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog