From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-eopbgr720097.outbound.protection.outlook.com ([40.107.72.97]:28208 "EHLO NAM05-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727356AbeIBRTE (ORCPT ); Sun, 2 Sep 2018 13:19:04 -0400 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: YueHaibing , Linus Walleij , Sasha Levin Subject: [PATCH AUTOSEL 4.18 008/131] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state Date: Sun, 2 Sep 2018 13:03:07 +0000 Message-ID: <20180902064601.183036-8-alexander.levin@microsoft.com> References: <20180902064601.183036-1-alexander.levin@microsoft.com> In-Reply-To: <20180902064601.183036-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: YueHaibing [ Upstream commit b5031b7db77dc47f474f0efc2b2552c32b7bb59d ] 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 Marv= ell Berlin SoCs") Signed-off-by: YueHaibing Reviewed-by: Jisheng Zhang Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/berlin/berlin.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/berlin/berlin.c b/drivers/pinctrl/berlin/berli= n.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) } =20 /* we will reallocate later */ - pctrl->functions =3D devm_kcalloc(&pdev->dev, - max_functions, - sizeof(*pctrl->functions), - GFP_KERNEL); + pctrl->functions =3D kcalloc(max_functions, + sizeof(*pctrl->functions), GFP_KERNEL); if (!pctrl->functions) return -ENOMEM; =20 @@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_= device *pdev) function++; } =20 - if (!found) + if (!found) { + kfree(pctrl->functions); return -EINVAL; + } =20 if (!function->groups) { function->groups =3D @@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_= device *pdev) sizeof(char *), GFP_KERNEL); =20 - if (!function->groups) + if (!function->groups) { + kfree(pctrl->functions); return -ENOMEM; + } } =20 groups =3D function->groups; --=20 2.17.1