From patchwork Wed Aug 2 09:03:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Pieralisi X-Patchwork-Id: 9876419 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 642B76041F for ; Wed, 2 Aug 2017 09:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5780B2621D for ; Wed, 2 Aug 2017 09:01:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C4BE2853B; Wed, 2 Aug 2017 09:01:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 003722766D for ; Wed, 2 Aug 2017 09:01:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752139AbdHBJBP (ORCPT ); Wed, 2 Aug 2017 05:01:15 -0400 Received: from foss.arm.com ([217.140.101.70]:50350 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752296AbdHBJBO (ORCPT ); Wed, 2 Aug 2017 05:01:14 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 96B1113D5; Wed, 2 Aug 2017 02:01:13 -0700 (PDT) Received: from red-moon (red-moon.cambridge.arm.com [10.1.206.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5D3873F3E1; Wed, 2 Aug 2017 02:01:12 -0700 (PDT) Date: Wed, 2 Aug 2017 10:03:07 +0100 From: Lorenzo Pieralisi To: Harunobu Kurokawa Cc: horms@verge.net.au, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI: rcar-pcie: Fix memory leak when no PCIe card is inserted Message-ID: <20170802090307.GA24167@red-moon> References: <20170802071320.28674-1-harunobu.kurokawa.dn@renesas.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170802071320.28674-1-harunobu.kurokawa.dn@renesas.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Aug 02, 2017 at 04:13:20PM +0900, Harunobu Kurokawa wrote: > When no PCIe card is inserted, there is a memory leak as > pci_free_resource_list is not called before returning. > > Signed-off-by: Harunobu Kurokawa > --- > drivers/pci/host/pcie-rcar.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c > index ac80fbb..9b06de6 100644 > --- a/drivers/pci/host/pcie-rcar.c > +++ b/drivers/pci/host/pcie-rcar.c > @@ -1190,14 +1190,15 @@ static int rcar_pcie_probe(struct platform_device *pdev) > > return 0; > > -err_free_bridge: > - pci_free_host_bridge(bridge); > - > err_pm_put: > pm_runtime_put(dev); > > err_pm_disable: > pm_runtime_disable(dev); > + > +err_free_bridge: > + pci_free_host_bridge(bridge); > + pci_free_resource_list(&pcie->resources); > return err; > } The error code path needs fixing but not like this (with a single patch lumping all fixes - well, actually it does not - together). Step one, patch below. Step two free the &pci->resources list (which IIUC was not freed even before commit 90634e854079) in a separate patch. Am I missing something ? Please apply, check and repost the patch if it is ok, thanks. -- >8 -- Subject: [PATCH] PCI: rcar: Fix error exit path Commit 90634e854079 ("PCI: rcar: Convert PCI scan API to pci_scan_root_bus_bridge()") converted PCI root bus scan API to the new pci_scan_root_bus_bridge() API; in the process some error paths were not updated correctly which may cause memory leaks. Fix the driver error exit path reinstating the previous correct error exit behaviour. Fixes: 90634e854079 ("PCI: rcar: Convert PCI scan API to pci_scan_root_bus_bridge()") Signed-off-by: Lorenzo Pieralisi --- drivers/pci/host/pcie-rcar.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index 246d485..007523e 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -471,10 +471,8 @@ static int rcar_pcie_enable(struct rcar_pcie *pcie) bridge->msi = &pcie->msi.chip; ret = pci_scan_root_bus_bridge(bridge); - if (ret < 0) { - kfree(bridge); + if (ret < 0) return ret; - } bus = bridge->bus; @@ -1190,14 +1188,15 @@ static int rcar_pcie_probe(struct platform_device *pdev) return 0; -err_free_bridge: - pci_free_host_bridge(bridge); - err_pm_put: pm_runtime_put(dev); err_pm_disable: pm_runtime_disable(dev); + +err_free_bridge: + pci_free_host_bridge(bridge); + return err; }