[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <lsq.1544392233.904390123@decadent.org.uk>
Date: Sun, 09 Dec 2018 21:50:33 +0000
From: Ben Hutchings <ben@...adent.org.uk>
To: linux-kernel@...r.kernel.org, stable@...r.kernel.org
CC: akpm@...ux-foundation.org,
"Linus Walleij" <linus.walleij@...aro.org>,
"Jisheng Zhang" <Jisheng.Zhang@...aptics.com>,
"YueHaibing" <yuehaibing@...wei.com>
Subject: [PATCH 3.16 101/328] pinctrl: berlin: fix 'pctrl->functions'
allocation in berlin_pinctrl_build_state
3.16.62-rc1 review patch. If anyone has any objections, please let me know.
------------------
From: YueHaibing <yuehaibing@...wei.com>
commit b5031b7db77dc47f474f0efc2b2552c32b7bb59d upstream.
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@...wei.com>
Reviewed-by: Jisheng Zhang <Jisheng.Zhang@...aptics.com>
Signed-off-by: Linus Walleij <linus.walleij@...aro.org>
[bwh: Backported to 3.16: berlin_pinctrl_state() was not yet converted
to devm_kcalloc()]
Signed-off-by: Ben Hutchings <ben@...adent.org.uk>
---
drivers/pinctrl/berlin/berlin.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
--- a/drivers/pinctrl/berlin/berlin.c
+++ b/drivers/pinctrl/berlin/berlin.c
@@ -237,9 +237,8 @@ static int berlin_pinctrl_build_state(st
}
/* we will reallocate later */
- pctrl->functions = devm_kzalloc(&pdev->dev,
- max_functions * sizeof(*pctrl->functions),
- GFP_KERNEL);
+ pctrl->functions = kcalloc(max_functions,
+ sizeof(*pctrl->functions), GFP_KERNEL);
if (!pctrl->functions)
return -ENOMEM;
@@ -277,8 +276,10 @@ static int berlin_pinctrl_build_state(st
function++;
}
- if (!found)
+ if (!found) {
+ kfree(pctrl->functions);
return -EINVAL;
+ }
if (!function->groups) {
function->groups =
@@ -286,8 +287,10 @@ static int berlin_pinctrl_build_state(st
function->ngroups * sizeof(char *),
GFP_KERNEL);
- if (!function->groups)
+ if (!function->groups) {
+ kfree(pctrl->functions);
return -ENOMEM;
+ }
}
groups = function->groups;
Powered by blists - more mailing lists