Skip to content

Commit

Permalink
pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_…
Browse files Browse the repository at this point in the history
…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: 3de68d3 ("pinctrl: berlin: add the core pinctrl driver for Marvell Berlin SoCs")
Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Reviewed-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
YueHaibing authored and Linus Walleij committed Aug 3, 2018
1 parent 40b25bc commit b5031b7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/pinctrl/berlin/berlin.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
}

/* we will reallocate later */
pctrl->functions = devm_kcalloc(&pdev->dev,
max_functions,
sizeof(*pctrl->functions),
GFP_KERNEL);
pctrl->functions = kcalloc(max_functions,
sizeof(*pctrl->functions), GFP_KERNEL);
if (!pctrl->functions)
return -ENOMEM;

Expand Down Expand Up @@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
function++;
}

if (!found)
if (!found) {
kfree(pctrl->functions);
return -EINVAL;
}

if (!function->groups) {
function->groups =
Expand All @@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev)
sizeof(char *),
GFP_KERNEL);

if (!function->groups)
if (!function->groups) {
kfree(pctrl->functions);
return -ENOMEM;
}
}

groups = function->groups;
Expand Down

0 comments on commit b5031b7

Please sign in to comment.