Skip to contentSkip to conversation

ACPI/PCI: Fix memory leak fix in pci_acpi_preserve_config

PATCH Applied Nirmoy Das 2 participants 3 messages Aug 25, 2025 – Aug 27, 2025

Subsystems (2)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH 1/1 ACPI/PCI: Fix memory leak fix in pci_acpi_preserve_config

The pci_acpi_preserve_config() function is leaking memory by returning early without freeing the ACPI object on success. Fix that by always freeing the obj which is not needed by the caller.

Fixes 9d7d5db8e78e ("PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge()")
---
 drivers/pci/pci-acpi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci-acpi.c +4 -2
index ddb25960ea47d..9369377725fa0 100644
@@ -122,6 +122,8 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
 
 bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
 {
+	bool ret = false;
+
 	if (ACPI_HANDLE(&host_bridge->dev)) {
 		union acpi_object *obj;
 
@@ -135,11 +137,11 @@ bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
 					      1, DSM_PCI_PRESERVE_BOOT_CONFIG,
 					      NULL, ACPI_TYPE_INTEGER);
 		if (obj && obj->integer.value == 0)
-			return true;
+			ret = true;
 		ACPI_FREE(obj);
 	}
 
-	return false;
+	return ret;
 }
 
 /* _HPX PCI Setting Record (Type 0); same as _HPP */
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · Nirmoy Das

The pci_acpi_preserve_config() function is leaking memory by returning early without freeing the ACPI object on success. Fix that by always freeing the obj which is not needed by the caller.

Fixes 9d7d5db8e78e ("PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge()")

Applied to pci/misc for v6.18, thanks!

Quoted 34 lines
---
 drivers/pci/pci-acpi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci-acpi.c +4 -2
index ddb25960ea47d..9369377725fa0 100644
@@ -122,6 +122,8 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
 
 bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
 {
+	bool ret = false;
+
 	if (ACPI_HANDLE(&host_bridge->dev)) {
 		union acpi_object *obj;
 
@@ -135,11 +137,11 @@ bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
 					      1, DSM_PCI_PRESERVE_BOOT_CONFIG,
 					      NULL, ACPI_TYPE_INTEGER);
 		if (obj && obj->integer.value == 0)
-			return true;
+			ret = true;
 		ACPI_FREE(obj);
 	}
 
-	return false;
+	return ret;
 }
 
 /* _HPX PCI Setting Record (Type 0); same as _HPP */
Signature · 1 line
2.43.0
author
#2 lore raw
Quoted 8 lines · Bjorn Helgaas
Quoted 6 lines · Nirmoy Das

The pci_acpi_preserve_config() function is leaking memory by returning early without freeing the ACPI object on success. Fix that by always freeing the obj which is not needed by the caller.

Fixes 9d7d5db8e78e ("PCI: Move PRESERVE_BOOT_CONFIG _DSM evaluation to pci_register_host_bridge()")

Applied to pci/misc for v6.18, thanks!

Thanks Bjorn!

Quoted 35 lines
Quoted 35 lines
---
  drivers/pci/pci-acpi.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/pci/pci-acpi.c +4 -2
index ddb25960ea47d..9369377725fa0 100644
@@ -122,6 +122,8 @@ phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle)
 
  bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
  {
+	bool ret = false;
+
  	if (ACPI_HANDLE(&host_bridge->dev)) {
  		union acpi_object *obj;
 
@@ -135,11 +137,11 @@ bool pci_acpi_preserve_config(struct pci_host_bridge *host_bridge)
  					      1, DSM_PCI_PRESERVE_BOOT_CONFIG,
  					      NULL, ACPI_TYPE_INTEGER);
  		if (obj && obj->integer.value == 0)
-			return true;
+			ret = true;
  		ACPI_FREE(obj);
  	}
 
-	return false;
+	return ret;
  }
 
  /* _HPX PCI Setting Record (Type 0); same as _HPP */
Signature · 1 line
2.43.0