Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp385942imm; Tue, 31 Jul 2018 21:14:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc0TUjjhcDjHKoM5f4VekAPU0wBtvdjIFhABrs1Bmci1UMt6gf6lHI3NFqzXoaT45/fl4yc X-Received: by 2002:a63:f804:: with SMTP id n4-v6mr23477829pgh.106.1533096865919; Tue, 31 Jul 2018 21:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533096865; cv=none; d=google.com; s=arc-20160816; b=If4E+iLvq/jVqdFq2VJCSadpgPZ1Po+eS+Z7aPu0LHiu77eg/eG0f8XC8gtUwmkNP2 G4lBXt1PFXFBZHOMlx8wQF8CtWrHW7lpw3ZscboxAjJrBcxohtzyOM8bStq1ZlOv57gJ NmFQGKJw21+gBUgqPH/Ak5ZEa70z2/yflTxgwgvzvuEAfLEbkdvrtkPkPNPHZvLVOUHy JhNCNNE3i+f1teXhTQ2rmFnK8lAeSQUHc4tkubx7gnB2XTyV+PZ6Xgi9Jzru72KjbHHx VCNcytgxtBzcaSJ0tJzEEHKDJx3aR1yFE9S+vFY3p7qwETn3OwWkIQ+6ILs8o0H0bNXp ITPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=birbG1o5l7eRMEDmVv72VsUTqqyYg9G3V00jED5HmzA=; b=S2MQKuklxQKzcYLaQsQq1gEGWMzv/xpervPiXy1Yd1icw2SZOD1b7MQNjbKNxDeSqs 6AWlDPbse4IM4jTTDDwX58YDcSIE+JFztzxUeg7AQvXV2UZpTSBMhGeCdPTreaFvQQKn nGIRd3wNvqtPKOKpEUwFNBUth1lja7PnPhgBNnVLINlyx62i/F98zR6U9PNT5xM1DUEx nbkY8NKX/pluSxJPhrYwR4X3qLOb0Eek3aS+AnJuX0h2gsMcpEzgXhHNYBl4977Fpe8i +oIdJ9IyoFmRykl8WaFZXU7lnE9u6jmFazqP10RsDv9t+sH+umRi51AxAFRnObjDVqQv cSIw== 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 k188-v6si15207407pgc.321.2018.07.31.21.13.59; Tue, 31 Jul 2018 21:14:25 -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 S1731950AbeHAF4H (ORCPT + 99 others); Wed, 1 Aug 2018 01:56:07 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:36040 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726960AbeHAF4H (ORCPT ); Wed, 1 Aug 2018 01:56:07 -0400 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 4BCE6DC469667; Wed, 1 Aug 2018 12:12:31 +0800 (CST) Received: from [127.0.0.1] (10.177.31.96) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.399.0; Wed, 1 Aug 2018 12:12:31 +0800 Subject: Re: [PATCH] pinctrl: berlin: fix 'pctrl->functions' allocation in berlin_pinctrl_build_state To: Jisheng Zhang References: <20180731142501.21888-1-yuehaibing@huawei.com> <20180801103645.5df924b9@xhacker.debian> CC: , , , , From: YueHaibing Message-ID: Date: Wed, 1 Aug 2018 12:12:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <20180801103645.5df924b9@xhacker.debian> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit 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 On 2018/8/1 10:36, Jisheng Zhang wrote: > Hi, > > On Tue, 31 Jul 2018 22:25:01 +0800 YueHaibing wrote: > >> 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. > > Good catch. Comments below. > >> >> 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); > > is it enough to just free one function? I think we need to free functions. Yep, should free 'pctrl->functions', Thanks! Will send v2. > >> 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); > > ditto > >> return -ENOMEM; >> + } >> } >> >> groups = function->groups; > > >