diff options
author | YueHaibing <yuehaibing@huawei.com> | 2018-08-01 01:10:49 -0400 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2018-08-03 13:28:15 -0400 |
commit | b5031b7db77dc47f474f0efc2b2552c32b7bb59d (patch) | |
tree | 05945a16717151f2cb1d3489f28cf52c0a1bb791 /drivers/pinctrl/berlin | |
parent | 40b25bce0adbe641a744d1291bc0e51fb7f3c3d8 (diff) |
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: 3de68d331c24 ("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>
Diffstat (limited to 'drivers/pinctrl/berlin')
-rw-r--r-- | drivers/pinctrl/berlin/berlin.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berlin.c index d6d183e9db17..b5903fffb3d0 100644 --- a/drivers/pinctrl/berlin/berlin.c +++ b/drivers/pinctrl/berlin/berlin.c | |||
@@ -216,10 +216,8 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) | |||
216 | } | 216 | } |
217 | 217 | ||
218 | /* we will reallocate later */ | 218 | /* we will reallocate later */ |
219 | pctrl->functions = devm_kcalloc(&pdev->dev, | 219 | pctrl->functions = kcalloc(max_functions, |
220 | max_functions, | 220 | sizeof(*pctrl->functions), GFP_KERNEL); |
221 | sizeof(*pctrl->functions), | ||
222 | GFP_KERNEL); | ||
223 | if (!pctrl->functions) | 221 | if (!pctrl->functions) |
224 | return -ENOMEM; | 222 | return -ENOMEM; |
225 | 223 | ||
@@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) | |||
257 | function++; | 255 | function++; |
258 | } | 256 | } |
259 | 257 | ||
260 | if (!found) | 258 | if (!found) { |
259 | kfree(pctrl->functions); | ||
261 | return -EINVAL; | 260 | return -EINVAL; |
261 | } | ||
262 | 262 | ||
263 | if (!function->groups) { | 263 | if (!function->groups) { |
264 | function->groups = | 264 | function->groups = |
@@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) | |||
267 | sizeof(char *), | 267 | sizeof(char *), |
268 | GFP_KERNEL); | 268 | GFP_KERNEL); |
269 | 269 | ||
270 | if (!function->groups) | 270 | if (!function->groups) { |
271 | kfree(pctrl->functions); | ||
271 | return -ENOMEM; | 272 | return -ENOMEM; |
273 | } | ||
272 | } | 274 | } |
273 | 275 | ||
274 | groups = function->groups; | 276 | groups = function->groups; |