Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp426499imm; Tue, 31 Jul 2018 22:12:50 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcDT91uk3cqhQ07pAiDU5L+VZrGcg3PBesj8uiRkXwRsilFNNOQUolsanpHoYo/wczOxcPM X-Received: by 2002:a17:902:7898:: with SMTP id q24-v6mr22608460pll.222.1533100370865; Tue, 31 Jul 2018 22:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533100370; cv=none; d=google.com; s=arc-20160816; b=MMcmLit4b6EXOwwnjgbpRGccx8IXnJ+lNICiWWp37WsKgPlJ9Q3usiOEvJx0OhvnyD 4Ih2No59a6zcj1xCF90Rik+Zgy6ZSfv0+h90o+UbB9Cn7gsR7GvBhvNCgcvhuLrjzEcG rUqRPhmoolkM141MJbCqvSTkKH6qqgcCvEt4nMFbjBmf8Q5lR5wVn9andf1L1HUKIqm1 bmqYkjy3VyuVSmJsz82+7N4XILw9ILDofhdobYfB/KmzZGe319QkOf01MKYrxfUuL4Ol JSSU5f5p800mnVs9rZZTcfdjDkZEpRgYg0AkENBtLzpZ8wt9rjZYSSq24a0aEK1Bf60r gMZA== 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=YNxEbAP044ngD/fxazB+t3tx2xTV3hVgkm5oqzE3Qlo=; b=sKavSn51Vj1SkpY5N27Qa4S1LAtfXnvbgPcUSQvufQlXbqoJ6SNghxRJuIUZLrLvSf MZU13q3vxP2iS1DHXrjYTr7OC2drnZJ54XTCHKbidq54M4Ggfrp8R9oX4YuMAxOisTti MTmIjgbl8+i51rO25DRbZZhlLLrlDclEb8iLeIpWUcaeuGtJ5oJKCSD2ukzNF/5yyTN2 wdtPlNrBdQBRyaR0BnqP1sLm6VtN5Ix3ZgZHQWD3ATzsdRbogW5VnSsWLIvi5Zb/aJ5m LqkW9kEvhyh4GTv+0YOXxoiszQrnptsujc5tIv+jmjg8p3kBYOM60HwTrhbxhjZ32ep2 nJgA== 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 s27-v6si14827962pgn.473.2018.07.31.22.12.36; Tue, 31 Jul 2018 22:12:50 -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 S2387434AbeHAGyt (ORCPT + 99 others); Wed, 1 Aug 2018 02:54:49 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:10200 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1733094AbeHAGyt (ORCPT ); Wed, 1 Aug 2018 02:54:49 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D83D520E9F7CF; Wed, 1 Aug 2018 13:10:59 +0800 (CST) Received: from localhost (10.177.31.96) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.399.0; Wed, 1 Aug 2018 13:10:53 +0800 From: YueHaibing To: , , , CC: , , YueHaibing Subject: [PATCH v3] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state Date: Wed, 1 Aug 2018 13:10:49 +0800 Message-ID: <20180801051049.21360-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 --- v2: free pctrl->functions instead of function as Jisheng Zhang suggested v3: v2 I send a wrong patch,this is the correct patch. --- 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..b5903ff 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(pctrl->functions); 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(pctrl->functions); return -ENOMEM; + } } groups = function->groups; -- 2.7.0