mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Bernd Schubert <bernd.schubert@itwm.fraunhofer.de>
Cc: "x86@kernel.org" <x86@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Bjorn Helgaas <bjorn.helgaas@hp.com>
Subject: Re: [PATCH] Fix a memory leak reported by kmemleak.
Date: Tue, 21 Jun 2011 13:46:01 +0100	[thread overview]
Message-ID: <20110621124601.GE29146@e102109-lin.cambridge.arm.com> (raw)
In-Reply-To: <20110621110853.2537133.20464.stgit@localhost.localdomain>

On Tue, Jun 21, 2011 at 12:08:53PM +0100, Bernd Schubert wrote:
> Memory allocated by get_current_resources() will be never free'ed
> if 'pci_use_crs' is not set.
> 
> Signed-off-by: Bernd Schubert <bernd.schubert@itwm.fraunhofer.de>
> ---
>  arch/x86/pci/acpi.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
> index 0972315..3ad040a 100644
> --- a/arch/x86/pci/acpi.c
> +++ b/arch/x86/pci/acpi.c
> @@ -228,8 +228,11 @@ static void add_resources(struct pci_root_info *info)
>  	int i;
>  	struct resource *res, *root, *conflict;
>  
> -	if (!pci_use_crs)
> +	if (!pci_use_crs) {
> +		kfree(info->res);
> +		kfree(info->name);
>  		return;
> +	}
>  
>  	coalesce_windows(info, IORESOURCE_MEM);
>  	coalesce_windows(info, IORESOURCE_IO);

Thanks for looking into this. I cc'ed Bjorn as he seems to be the last
one changing this file. I'm not familiar with part of the kernel, so not
sure whether info->res or info->name could be used somewhere else under
certain conditions.

An alternative patch (just to keep allocation/freeing in the same
function):

diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
index 0972315..684cf82 100644
--- a/arch/x86/pci/acpi.c
+++ b/arch/x86/pci/acpi.c
@@ -228,9 +228,6 @@ static void add_resources(struct pci_root_info *info)
 	int i;
 	struct resource *res, *root, *conflict;
 
-	if (!pci_use_crs)
-		return;
-
 	coalesce_windows(info, IORESOURCE_MEM);
 	coalesce_windows(info, IORESOURCE_IO);
 
@@ -286,8 +283,11 @@ get_current_resources(struct acpi_device *device, int busnum,
 	acpi_walk_resources(device->handle, METHOD_NAME__CRS, setup_resource,
 				&info);
 
-	add_resources(&info);
-	return;
+	if (pci_use_crs) {
+		add_resources(&info);
+		return;
+	}
+	kfree(info.name);
 
 name_alloc_fail:
 	kfree(info.res);

-- 
Catalin


      reply	other threads:[~2011-06-21 12:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-21 11:08 Bernd Schubert
2011-06-21 12:46 ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110621124601.GE29146@e102109-lin.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=bernd.schubert@itwm.fraunhofer.de \
    --cc=bjorn.helgaas@hp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®