Commit a4925311 authored by YueHaibing's avatar YueHaibing Committed by Linus Walleij

pinctrl: sunxi: fix 'pctrl->functions' allocation in sunxi_pinctrl_build_state

fixes following Smatch static check warning:

 ./drivers/pinctrl/sunxi/pinctrl-sunxi.c:1112 sunxi_pinctrl_build_state()
 warn: passing devm_ allocated variable to kfree. 'pctrl->functions'

As we will be calling krealloc() on pointer 'pctrl->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: 0e37f88d ("ARM: sunxi: Add pinctrl driver for Allwinner SoCs")
Signed-off-by: default avatarYueHaibing <yuehaibing@huawei.com>
Acked-by: default avatarMaxime Ripard <maxime.ripard@bootlin.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent bb8d8466
...@@ -1079,10 +1079,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) ...@@ -1079,10 +1079,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
* We suppose that we won't have any more functions than pins, * We suppose that we won't have any more functions than pins,
* we'll reallocate that later anyway * we'll reallocate that later anyway
*/ */
pctl->functions = devm_kcalloc(&pdev->dev, pctl->functions = kcalloc(pctl->ngroups,
pctl->ngroups, sizeof(*pctl->functions),
sizeof(*pctl->functions), GFP_KERNEL);
GFP_KERNEL);
if (!pctl->functions) if (!pctl->functions)
return -ENOMEM; return -ENOMEM;
...@@ -1133,8 +1132,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) ...@@ -1133,8 +1132,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
func_item = sunxi_pinctrl_find_function_by_name(pctl, func_item = sunxi_pinctrl_find_function_by_name(pctl,
func->name); func->name);
if (!func_item) if (!func_item) {
kfree(pctl->functions);
return -EINVAL; return -EINVAL;
}
if (!func_item->groups) { if (!func_item->groups) {
func_item->groups = func_item->groups =
...@@ -1142,8 +1143,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) ...@@ -1142,8 +1143,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev)
func_item->ngroups, func_item->ngroups,
sizeof(*func_item->groups), sizeof(*func_item->groups),
GFP_KERNEL); GFP_KERNEL);
if (!func_item->groups) if (!func_item->groups) {
kfree(pctl->functions);
return -ENOMEM; return -ENOMEM;
}
} }
func_grp = func_item->groups; func_grp = func_item->groups;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment