1 |
From fa72414bc43eccdef8c1b620b96b0ff5fd9853a4 Mon Sep 17 00:00:00 2001 |
2 |
From: YueHaibing <yuehaibing@huawei.com> |
3 |
Date: Fri, 21 Sep 2018 09:59:41 +0800 |
4 |
Subject: [PATCH 051/145] pinctrl: sunxi: fix 'pctrl->functions' allocation in |
5 |
sunxi_pinctrl_build_state |
6 |
|
7 |
[ Upstream commit a4925311a5443126ecc90671a1604ea7b0f5b32e ] |
8 |
|
9 |
fixes following Smatch static check warning: |
10 |
|
11 |
./drivers/pinctrl/sunxi/pinctrl-sunxi.c:1112 sunxi_pinctrl_build_state() |
12 |
warn: passing devm_ allocated variable to kfree. 'pctrl->functions' |
13 |
|
14 |
As we will be calling krealloc() on pointer 'pctrl->functions', which means |
15 |
kfree() will be called in there, devm_kzalloc() shouldn't be used with |
16 |
the allocation in the first place. Fix the warning by calling kcalloc() |
17 |
and managing the free procedure in error path on our own. |
18 |
|
19 |
Fixes: 0e37f88d9ad8 ("ARM: sunxi: Add pinctrl driver for Allwinner SoCs") |
20 |
Signed-off-by: YueHaibing <yuehaibing@huawei.com> |
21 |
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com> |
22 |
Signed-off-by: Linus Walleij <linus.walleij@linaro.org> |
23 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
24 |
--- |
25 |
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 15 +++++++++------ |
26 |
1 file changed, 9 insertions(+), 6 deletions(-) |
27 |
|
28 |
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c |
29 |
index 4d9bf9b3e9f3..26ebedc1f6d3 100644 |
30 |
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c |
31 |
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c |
32 |
@@ -1079,10 +1079,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) |
33 |
* We suppose that we won't have any more functions than pins, |
34 |
* we'll reallocate that later anyway |
35 |
*/ |
36 |
- pctl->functions = devm_kcalloc(&pdev->dev, |
37 |
- pctl->ngroups, |
38 |
- sizeof(*pctl->functions), |
39 |
- GFP_KERNEL); |
40 |
+ pctl->functions = kcalloc(pctl->ngroups, |
41 |
+ sizeof(*pctl->functions), |
42 |
+ GFP_KERNEL); |
43 |
if (!pctl->functions) |
44 |
return -ENOMEM; |
45 |
|
46 |
@@ -1133,8 +1132,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) |
47 |
|
48 |
func_item = sunxi_pinctrl_find_function_by_name(pctl, |
49 |
func->name); |
50 |
- if (!func_item) |
51 |
+ if (!func_item) { |
52 |
+ kfree(pctl->functions); |
53 |
return -EINVAL; |
54 |
+ } |
55 |
|
56 |
if (!func_item->groups) { |
57 |
func_item->groups = |
58 |
@@ -1142,8 +1143,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) |
59 |
func_item->ngroups, |
60 |
sizeof(*func_item->groups), |
61 |
GFP_KERNEL); |
62 |
- if (!func_item->groups) |
63 |
+ if (!func_item->groups) { |
64 |
+ kfree(pctl->functions); |
65 |
return -ENOMEM; |
66 |
+ } |
67 |
} |
68 |
|
69 |
func_grp = func_item->groups; |
70 |
-- |
71 |
2.19.1 |
72 |
|