Skip to content

Commit 631b2af

Browse files
Zhe Qiaokwilczynski
authored andcommitted
PCI/ACPI: Fix allocated memory release on error in pci_acpi_scan_root()
In the pci_acpi_scan_root() function, when creating a PCI bus fails, we need to free up the previously allocated memory, which can avoid invalid memory usage and save resources. Fixes: 789befd ("arm64: PCI: Migrate ACPI related functions to pci-acpi.c") Signed-off-by: Zhe Qiao <[email protected]> [kwilczynski: commit log] Signed-off-by: Krzysztof Wilczyński <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0af2f6b commit 631b2af

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

drivers/pci/pci-acpi.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,24 +1676,19 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
16761676
return NULL;
16771677

16781678
root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
1679-
if (!root_ops) {
1680-
kfree(ri);
1681-
return NULL;
1682-
}
1679+
if (!root_ops)
1680+
goto free_ri;
16831681

16841682
ri->cfg = pci_acpi_setup_ecam_mapping(root);
1685-
if (!ri->cfg) {
1686-
kfree(ri);
1687-
kfree(root_ops);
1688-
return NULL;
1689-
}
1683+
if (!ri->cfg)
1684+
goto free_root_ops;
16901685

16911686
root_ops->release_info = pci_acpi_generic_release_info;
16921687
root_ops->prepare_resources = pci_acpi_root_prepare_resources;
16931688
root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops;
16941689
bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg);
16951690
if (!bus)
1696-
return NULL;
1691+
goto free_cfg;
16971692

16981693
/* If we must preserve the resource configuration, claim now */
16991694
host = pci_find_host_bridge(bus);
@@ -1710,6 +1705,14 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
17101705
pcie_bus_configure_settings(child);
17111706

17121707
return bus;
1708+
1709+
free_cfg:
1710+
pci_ecam_free(ri->cfg);
1711+
free_root_ops:
1712+
kfree(root_ops);
1713+
free_ri:
1714+
kfree(ri);
1715+
return NULL;
17131716
}
17141717

17151718
void pcibios_add_bus(struct pci_bus *bus)

0 commit comments

Comments
 (0)