提交 b5031b7d 编写于 作者: Y YueHaibing 提交者: Linus Walleij

pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state

fixes following Smatch static check warning:

 drivers/pinctrl/berlin/berlin.c:237 berlin_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: 3de68d33 ("pinctrl: berlin: add the core pinctrl driver for Marvell Berlin SoCs")
Signed-off-by: NYueHaibing <yuehaibing@huawei.com>
Reviewed-by: NJisheng Zhang <Jisheng.Zhang@synaptics.com>
Signed-off-by: NLinus Walleij <linus.walleij@linaro.org>
上级 40b25bce
...@@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
} }
/* we will reallocate later */ /* we will reallocate later */
pctrl->functions = devm_kcalloc(&pdev->dev, pctrl->functions = kcalloc(max_functions,
max_functions, sizeof(*pctrl->functions), GFP_KERNEL);
sizeof(*pctrl->functions),
GFP_KERNEL);
if (!pctrl->functions) if (!pctrl->functions)
return -ENOMEM; return -ENOMEM;
...@@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
function++; function++;
} }
if (!found) if (!found) {
kfree(pctrl->functions);
return -EINVAL; return -EINVAL;
}
if (!function->groups) { if (!function->groups) {
function->groups = function->groups =
...@@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) ...@@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
sizeof(char *), sizeof(char *),
GFP_KERNEL); GFP_KERNEL);
if (!function->groups) if (!function->groups) {
kfree(pctrl->functions);
return -ENOMEM; return -ENOMEM;
}
} }
groups = function->groups; groups = function->groups;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册