Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 731BCC433EF for ; Wed, 6 Jul 2022 14:33:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Message-ID:MIME-Version:References: In-Reply-To:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tAy7QtEMJMfgIVPNXn1AFIXykb2sQS2UzQve4KYh0h0=; b=H0l0/AwUrVqBqD p32X2x8seMq6qCITL6io7VaYR1w5LWlKC+2f9wURyBpuclWy/1v5ZHx4nOWQoLEGYHLajYypqoOsX j8qc00KzXzhG+P0sI8XukteKGVDR0NT9BHDo/3NDpn96uoYoMt2E1jV4t2TbarAXwvkDQrs2G389S IDgVhj3X03XVyCWqUgeyRrZGbhtKCEGdCHIwW3E9bw8MZHUgGonxApG/fccipJnlu2dY8hMereD3k V2hVKtGxzPmC/q5O0jNXfmifr6VeH/nULMqHlbSq5B7kkoNZG4LLr+09EmOc8IEZEcebNL9A7is1q Xc8uVBlxpcTP+0OEegVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o964V-00AeTw-KU; Wed, 06 Jul 2022 14:32:07 +0000 Received: from m1564.mail.126.com ([220.181.15.64]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o964R-00AePE-1T for linux-arm-kernel@lists.infradead.org; Wed, 06 Jul 2022 14:32:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:Subject:MIME-Version:Message-ID; bh=JYbx6 gN+1bjVN1GphLMv4c556L7k1xm/P9NYFAnKSfc=; b=JTLmcC6Vsp3I1V1k3QG4R vzBhFi7rxEOBcgBNFkgn5lHcdYhW0eg3uAR/GNXBQ7g9kBGZHBTRhqtZBLdEnV8O aGxy8uDhw9TodMAZfBgEbodEy8zIA+YVvxWJFC4eQiQLNSsHVWWXT19Z2h9eOybd 9BttcJ4n2R+LK28XDSRQ6s= Received: from windhl$126.com ( [124.16.139.61] ) by ajax-webmail-wmsvr64 (Coremail) ; Wed, 6 Jul 2022 22:30:54 +0800 (CST) X-Originating-IP: [124.16.139.61] Date: Wed, 6 Jul 2022 22:30:54 +0800 (CST) From: "Liang He" To: "Arnd Bergmann" Cc: "Florian Fainelli" , bcm-kernel-feedback-list , "Linux ARM" Subject: Re:Re: [PATCH v2] soc: brcmstb: pm-arm: Fix refcount leak and __iomem leak bugs X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT5.0.13 build 20220113(9671e152) Copyright (c) 2002-2022 www.mailtech.cn 126com In-Reply-To: References: <20220706083433.303135-1-windhl@126.com> MIME-Version: 1.0 Message-ID: <56e84ee6.7abf.181d3ebcbfe.Coremail.windhl@126.com> X-Coremail-Locale: zh_CN X-CM-TRANSID: QMqowACXn3OfnMVirNBGAA--.59219W X-CM-SenderInfo: hzlqvxbo6rjloofrz/1tbi2h82F1uwMWuIVgAAsL X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220706_073203_482883_A7987862 X-CRM114-Status: GOOD ( 15.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org At 2022-07-06 22:16:31, "Arnd Bergmann" wrote: >On Wed, Jul 6, 2022 at 10:34 AM Liang He wrote: >> >> In brcmstb_pm_probe(), there are two kinds of leak bugs: >> >> (1) we need to add of_node_put() when for_each__matching_node() breaks >> (2) we need to add iounmap() for each iomap in fail path >> >> Fixes: 0b741b8234c8 ("soc: bcm: brcmstb: Add support for S2/S3/S5 suspend states (ARM)") >> Signed-off-by: Liang He >> --- >> changelog: >> >> v2: fix __iomem leak bug advised by Arnd > >This looks mostly ok, but some of it is not very readable. > >> @@ -711,7 +714,8 @@ static int brcmstb_pm_probe(struct platform_device *pdev) >> (const void **)&ddr_phy_data); >> if (IS_ERR(base)) { >> pr_err("error mapping DDR PHY\n"); >> - return PTR_ERR(base); >> + ret = PTR_ERR(base); >> + goto ddr_phy_err; >> } >> ctrl.support_warm_boot = ddr_phy_data->supports_warm_boot; >> ctrl.pll_status_offset = ddr_phy_data->pll_status_offset; >> @@ -727,21 +731,25 @@ static int brcmstb_pm_probe(struct platform_device *pdev) >> */ >> ctrl.warm_boot_offset = ddr_phy_data->warm_boot_offset; >> >> + j = ctrl.num_memc; > >I think the driver is confusing because it only supports a single instance and >stores the data in a global 'ctrl' structure. When you get into the probe >function, the value here should always be '0'. This also means it won't >work correctly when it runs across deferred probing (you can ignore that >bug, but maybe someone else should address this). > >Removing the 'j' variable from the function would make this more readable. > Hi, Arnd, Based on your explaination, removing 'j' also means following patch 'for (i = j; i < ctrl.num_memc; i++)' to release 'ctrl.memcs[i].ddr_shimphy_base' should start from i=0, right? If yes, I will send a new version patch. >> @@ -779,21 +791,24 @@ static int brcmstb_pm_probe(struct platform_device *pdev) >> dn = of_find_matching_node(NULL, sram_dt_ids); >> if (!dn) { >> pr_err("SRAM not found\n"); >> - return -EINVAL; >> + ret = -EINVAL; >> + goto brcmstb_memc_err; >> } >> >> ret = brcmstb_init_sram(dn); >> of_node_put(dn); > >There is another ioremap inside of brcmstb_init_sram() that should be cleaned up >in the error path if the kmalloc fails or dma_map_single fails. > Thanks, I will add 'iounmap(ctrl->ctrl.boot_sram)' in fail path. >> if (ret) { >> pr_err("error setting up SRAM for PM\n"); >> - return ret; >> + goto brcmstb_memc_err; >> } >> >> ctrl.pdev = pdev; >> >> ctrl.s3_params = kmalloc(sizeof(*ctrl.s3_params), GFP_KERNEL); >> - if (!ctrl.s3_params) >> - return -ENOMEM; >> + if (!ctrl.s3_params) { >> + ret = -ENOMEM; >> + goto brcmstb_memc_err; >> + } >> ctrl.s3_params_pa = dma_map_single(&pdev->dev, ctrl.s3_params, >> sizeof(*ctrl.s3_params), >> DMA_TO_DEVICE); > > Arnd Thanks all your help, Liang _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel