Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp176222imd; Wed, 31 Oct 2018 16:51:16 -0700 (PDT) X-Google-Smtp-Source: AJdET5dWPEPs2K5tnWMKxTc9w97TdIdPVzo0e2JWRl4VX+Nno3lc32F1RR92AwCoL3piOPWeEIBG X-Received: by 2002:a63:dc54:: with SMTP id f20mr5096379pgj.410.1541029876246; Wed, 31 Oct 2018 16:51:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029876; cv=none; d=google.com; s=arc-20160816; b=aCa/Kk7j+MM5rc/hUB8cTSVTk9BOPZpZGBiLjx4X9KPXwwmAxBVVjXB4LXUbfOQEh3 VSGXna8kGxxjWwwvgY3pEyUzFoZkWW2+OHSNGtNlz/92ll8J8XhSTZSbKaUmUpXpE3uB xefB+TbXGeqUYEyeqJBexa+cXPk8Z5NyJdMmvKoRpuVbZ8YA8yPA+QIiL0gGjKd5l8JG ga2JNmiCev+NuDjsblelavH5lu6ePcD9HdXg6HJe+BbIFYJdC8PUE5s+U5wVXPFpubzJ Y86UaV6AkYSapuKJ10A2U0dbMnU4Njeh0GP42RMn/AHLD0mAKZtyW/jX0yXoP+hVSsqu LDzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=eOcMilh7IbYCuluK3APN/n4uzSaHn1wjUVJN3GeSiOY=; b=e/iD8St/OnIWrVULZ1/88kgvn1phmdTVNNh3KzNKQ21UTxMtNGbv8TwIIM760cldIx M4G382HIrKzWCRMpsk5p+mHg/ukpxBa53MMSqrvyV0AieN0rmae1eshenvaKRbNgPPvX EpHPnm4ISlGHSzzfpMgg4psvr43DCdq4YRnXH7ZHh4pw7MqocaL2SRzo+C5z3EGzmsqy gxDApOyMheBpumCGz6kBBtTRdhxW14Xm3sZ0E3vztsV0fz0YRYh/5wf5BMBMitOYAy1j PzxUvJGAxSHaPKvy+LUNbvi+Nb/brsc0P58I+6r99u7Stmt3OQaQgXb2+CzsP05jOS+I D6pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dsn4UG+l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o22-v6si17376092pfk.50.2018.10.31.16.51.01; Wed, 31 Oct 2018 16:51:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dsn4UG+l; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728233AbeKAIGl (ORCPT + 99 others); Thu, 1 Nov 2018 04:06:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:53726 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728170AbeKAIGk (ORCPT ); Thu, 1 Nov 2018 04:06:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0002820664; Wed, 31 Oct 2018 23:06:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027189; bh=3jNxAO5z5jxM6hlgB0cbf7krl/KNnNIplASNPyPZSAw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dsn4UG+lcAq3gEuLR/2U1dEWvla5llVH/JUExxeMQzVgN62Ji99dyv7apu0mCRFXV vKLrg2oTXTlppVeIEaSF64/RvD14rHCyf9mGQHRif7q2Lb6LsaL26pctS1W8WClEM2 XFXeKP77SbVcxqZ0lhvNnVC1QlrltS3ncnJ4BCA8= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: YueHaibing , Linus Walleij , Sasha Levin Subject: [PATCH AUTOSEL 4.19 052/146] pinctrl: sunxi: fix 'pctrl->functions' allocation in sunxi_pinctrl_build_state Date: Wed, 31 Oct 2018 19:04:07 -0400 Message-Id: <20181031230541.28822-52-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: YueHaibing [ Upstream commit a4925311a5443126ecc90671a1604ea7b0f5b32e ] fixes following Smatch static check warning: ./drivers/pinctrl/sunxi/pinctrl-sunxi.c:1112 sunxi_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: 0e37f88d9ad8 ("ARM: sunxi: Add pinctrl driver for Allwinner SoCs") Signed-off-by: YueHaibing Acked-by: Maxime Ripard Signed-off-by: Linus Walleij Signed-off-by: Sasha Levin --- drivers/pinctrl/sunxi/pinctrl-sunxi.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c index 4d9bf9b3e9f3..26ebedc1f6d3 100644 --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c @@ -1079,10 +1079,9 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) * We suppose that we won't have any more functions than pins, * we'll reallocate that later anyway */ - pctl->functions = devm_kcalloc(&pdev->dev, - pctl->ngroups, - sizeof(*pctl->functions), - GFP_KERNEL); + pctl->functions = kcalloc(pctl->ngroups, + sizeof(*pctl->functions), + GFP_KERNEL); if (!pctl->functions) return -ENOMEM; @@ -1133,8 +1132,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) func_item = sunxi_pinctrl_find_function_by_name(pctl, func->name); - if (!func_item) + if (!func_item) { + kfree(pctl->functions); return -EINVAL; + } if (!func_item->groups) { func_item->groups = @@ -1142,8 +1143,10 @@ static int sunxi_pinctrl_build_state(struct platform_device *pdev) func_item->ngroups, sizeof(*func_item->groups), GFP_KERNEL); - if (!func_item->groups) + if (!func_item->groups) { + kfree(pctl->functions); return -ENOMEM; + } } func_grp = func_item->groups; -- 2.17.1