Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5221091imm; Tue, 31 Jul 2018 07:27:45 -0700 (PDT) X-Google-Smtp-Source: AAOMgpegu/HB0M4zeh/EyIaITpsbFXzRW+UaelcQPCUU0VY1k6V1IAiC+YT3hSsznCjHfmD+Un1s X-Received: by 2002:a63:d002:: with SMTP id z2-v6mr1798359pgf.262.1533047265177; Tue, 31 Jul 2018 07:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533047265; cv=none; d=google.com; s=arc-20160816; b=fb70NSh26tIRTPmS72i141eJF39OU7egm0rubnQ3fWS/zR3aqSid+zyKXIQELzFMek C8Td0xINnOzovCSNvdbdynk9qKMMCcwg40F2LwP/O6z+uq+mD4ixfKQ2kIoNLJdrUX5l OeFzGInpb42boyZVb0AeoLXoeWpViMrMSbGd6M8EKNRXaEr0YUJDUL9db/yKOo5rI794 fl1ZCf7ydrFMTjVeJ/cWBNJ3ljlMeGMYoEnTDitUY7Sgrj4BW5PG5FQfE1GuYAEFzDrB djp+mKxRMqj63m3JJ8KuKrNzonvM0QH8cHQ4c6F3h3ZZkFPHV6LUqEhFxHT4IE1GQq2X bQMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=iGG9hm2RsjSy389a0Tgx5BvgbVr01471eNoIIMAPfFY=; b=YxWQJD4L6HZvFVr4IqPVLveCbEvuhDggjb7QQu/hENWN32k0sDzEbNW1lVj/5lTj7A aGvHfjx/JCEw932IE7ZUErbll9udXXKFdeNC4qo9Bgh8nVI7tpJPcgKBjbz1vik2Geah K52XAlKB9VRIofnVeDRQ71hCFXa1DHRgTnzeArw9ua8O80Z2jb7VGHd1QhqTTlXQjvxf kE6cxYdhuUBDuNtHCtwJ8RC1LySJVfuZPyzhosC8Sg8+nyVuyqSxMGwN/Pa3xzlo1rZN pUfta9Ll9rEJgEcTkwBg9uZak+WIaqByX7eUOv+/dbuOf6ZH0GVgUQ8rzboXNgk842gj hNMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v123-v6si14252577pfb.324.2018.07.31.07.27.31; Tue, 31 Jul 2018 07:27:45 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732392AbeGaQGj (ORCPT + 99 others); Tue, 31 Jul 2018 12:06:39 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:10158 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732222AbeGaQGi (ORCPT ); Tue, 31 Jul 2018 12:06:38 -0400 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 759B0F78F04A0; Tue, 31 Jul 2018 22:25:55 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.399.0; Tue, 31 Jul 2018 22:25:46 +0800 From: YueHaibing To: , , , CC: , , YueHaibing Subject: [PATCH] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state Date: Tue, 31 Jul 2018 22:25:01 +0800 Message-ID: <20180731142501.21888-1-yuehaibing@huawei.com> X-Mailer: git-send-email 2.10.2.windows.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.31.96] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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/berlin.c index d6d183e..db2afb2 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) } /* we will reallocate later */ - pctrl->functions = devm_kcalloc(&pdev->dev, - max_functions, - sizeof(*pctrl->functions), - GFP_KERNEL); + pctrl->functions = kcalloc(max_functions, + sizeof(*pctrl->functions), GFP_KERNEL); if (!pctrl->functions) return -ENOMEM; @@ -257,8 +255,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) function++; } - if (!found) + if (!found) { + kfree(function); return -EINVAL; + } if (!function->groups) { function->groups = @@ -267,8 +267,10 @@ static int berlin_pinctrl_build_state(struct platform_device *pdev) sizeof(char *), GFP_KERNEL); - if (!function->groups) + if (!function->groups) { + kfree(function); return -ENOMEM; + } } groups = function->groups; -- 2.7.0