Browse Source

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

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.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: cbff0c4d27f4 ("pinctrl: add ZTE ZX pinctrl driver support")
Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Shawn Guo 8 years ago
parent
commit
bba2e87126
1 changed files with 4 additions and 3 deletions
  1. 4 3
      drivers/pinctrl/zte/pinctrl-zx.c

+ 4 - 3
drivers/pinctrl/zte/pinctrl-zx.c

@@ -295,8 +295,7 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 	pctldev->num_groups = ngroups;
 	pctldev->num_groups = ngroups;
 
 
 	/* Build function list from pin mux functions */
 	/* 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)
 	if (!functions)
 		return -ENOMEM;
 		return -ENOMEM;
 
 
@@ -367,8 +366,10 @@ static int zx_pinctrl_build_state(struct platform_device *pdev)
 						func->num_group_names *
 						func->num_group_names *
 						sizeof(*func->group_names),
 						sizeof(*func->group_names),
 						GFP_KERNEL);
 						GFP_KERNEL);
-				if (!func->group_names)
+				if (!func->group_names) {
+					kfree(functions);
 					return -ENOMEM;
 					return -ENOMEM;
+				}
 			}
 			}
 
 
 			group = func->group_names;
 			group = func->group_names;