Fix a memory leak reported by kmemleak.
PATCH 1/1 Fix a memory leak reported by kmemleak.
Memory allocated by get_current_resources() will be never free'ed if 'pci_use_crs' is not set.
Signed-off-by Bernd Schubert <[email protected]>
--- arch/x86/pci/acpi.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
arch/x86/pci/acpi.c +4 -1
@@ -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 );
Quoted 15 lines · Bernd Schubert
Memory allocated by
get_current_resources()will be never free'ed if 'pci_use_crs' is not set.Signed-off-by Bernd Schubert <[email protected]>--- arch/x86/pci/acpi.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)arch/x86/pci/acpi.c +0
-0@@ -228,8 +228,11 @@ static void add_resources(struct pci_root_info *info)int i;struct resource *res, *root, *conflict;
arch/x86/pci/acpi.c static void add_resources(struct pci_root_info *info) · line 238
Quoted 10 lines
arch/x86/pci/acpi.c +4
-1-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):
arch/x86/pci/acpi.c +5 -5
@@ -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);
Signature · 1 line
Catalin