Skip to contentSkip to conversation

pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

PATCH New Shawn Guo 3 participants 5 messages Jul 16, 2017 – Aug 2, 2017

Subsystems (2)
lore
Share & tools
lore

Shawn Guo

author
#0 lore raw

PATCH 1/1 pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

From: Shawn Guo <[email protected]>

It fixes the following Smatch static check warning:

drivers/pinctrl/zte/pinctrl-zx.c:338 zx_pinctrl_build_state()
warn: passing devm_ allocated variable to kfree.

As we will be calling krealloc() on pointer 'functions', which means kfree() will be called in there, devm_kzalloc() shouldn't be used with the allocation in the first place. Fix the warning by calling kcalloc() and managing the free procedure in error path on our own.

Fixes cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support")
---
 drivers/pinctrl/zte/pinctrl-zx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/pinctrl/zte/pinctrl-zx.c +4 -3
index f828ee340a98..ded366bb6564 100644
@@ -295,8 +295,7 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 	pctldev->num_groups = ngroups;
 
 	/* Build function list from pin mux functions */
-	functions = devm_kzalloc(&pdev->dev, info->npins * sizeof(*functions),
-				 GFP_KERNEL);
+	functions = kcalloc(info->npins, sizeof(*functions), GFP_KERNEL);
 	if (!functions)
 		return -ENOMEM;
 
@@ -367,8 +366,10 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 						func->num_group_names *
 						sizeof(*func->group_names),
 						GFP_KERNEL);
-				if (!func->group_names)
+				if (!func->group_names) {
+					kfree(functions);
 					return -ENOMEM;
+				}
 			}
 
 			group = func->group_names;
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

Shouldn't there be a free if the remove function? I'm not even sure where the remove function is so I don't know.

regards,
dan carpenter

author
#2 lore raw

PATCH 1/1 pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

Quoted 2 lines · Dan Carpenter

Shouldn't there be a free if the remove function? I'm not even sure where the remove function is so I don't know.

As the pinctrl driver is essential for the platform, it's always a builtin_platform_driver which we do not even have a remove function.

Shawn

#3 lore raw

PATCH 1/1 pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

Quoted 7 lines · Shawn Guo
Quoted 2 lines · Dan Carpenter

Shouldn't there be a free if the remove function? I'm not even sure where the remove function is so I don't know.

As the pinctrl driver is essential for the platform, it's always a builtin_platform_driver which we do not even have a remove function.

Ah. Good deal, then.

regards,
dan carpenter

#4 lore raw

PATCH 1/1 pinctrl: zte: fix 'functions' allocation in zx_pinctrl_build_state()

In reply to Shawn Guo
Quoted 7 lines · Shawn Guo

From: Shawn Guo <[email protected]>

It fixes the following Smatch static check warning:

drivers/pinctrl/zte/pinctrl-zx.c:338 zx_pinctrl_build_state()
warn: passing devm_ allocated variable to kfree.

Quoted 8 lines

As we will be calling krealloc() on pointer 'functions', which means kfree() will be called in there, devm_kzalloc() shouldn't be used with the allocation in the first place. Fix the warning by calling kcalloc() and managing the free procedure in error path on our own.

Fixes cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support")

Patch applied.

Yours,
Linus Walleij