* [PATCH] ACPI: pci: Release excess memory usage.
@ 2025-04-28 8:56 Zhe Qiao
2025-04-28 16:35 ` Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Zhe Qiao @ 2025-04-28 8:56 UTC (permalink / raw)
To: qiaozhe, rafael, lenb, bhelgaas; +Cc: linux-acpi, linux-pci, linux-kernel
In the pci_acpi_scan_root() function, if the PCI bus creation fails,
the allocated memory should be released to avoid memory occupation.
Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>
---
drivers/pci/pci-acpi.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index af370628e583..b008dbed7077 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1683,9 +1683,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
ri->cfg = pci_acpi_setup_ecam_mapping(root);
if (!ri->cfg) {
- kfree(ri);
- kfree(root_ops);
- return NULL;
+ goto cleanup_exit;
}
root_ops->release_info = pci_acpi_generic_release_info;
@@ -1693,7 +1691,7 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
root_ops->pci_ops = (struct pci_ops *)&ri->cfg->ops->pci_ops;
bus = acpi_pci_root_create(root, root_ops, &ri->common, ri->cfg);
if (!bus)
- return NULL;
+ goto cleanup_exit;
/* If we must preserve the resource configuration, claim now */
host = pci_find_host_bridge(bus);
@@ -1710,6 +1708,11 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
pcie_bus_configure_settings(child);
return bus;
+
+cleanup_exit:
+ kfree(root_ops);
+ kfree(ri);
+ return NULL;
}
void pcibios_add_bus(struct pci_bus *bus)
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ACPI: pci: Release excess memory usage
2025-04-28 8:56 [PATCH] ACPI: pci: Release excess memory usage Zhe Qiao
@ 2025-04-28 16:35 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-04-28 16:35 UTC (permalink / raw)
To: Zhe Qiao, linux-acpi, linux-pci
Cc: LKML, Bjorn Helgaas, Len Brown, Rafael J. Wysocki
> In the pci_acpi_scan_root() function, if the PCI bus creation fails,
failed?
> the allocated memory should be released to avoid memory occupation.
Do you propose to complete the exception handling?
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc4#n145
See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc4#n94
…
> +++ b/drivers/pci/pci-acpi.c
…
> @@ -1710,6 +1708,11 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
> pcie_bus_configure_settings(child);
>
> return bus;
> +
> +cleanup_exit:
How do you think about to use the label “free_root_ops”?
> + kfree(root_ops);
I suggest to use another label “free_ri” so that a bit of duplicate exception handling code
can be avoided from a previous if branch.
> + kfree(ri);
> + return NULL;
> }
…
How do you think about to benefit any more from the application of the attribute “__free”?
https://elixir.bootlin.com/linux/v6.15-rc4/source/include/linux/slab.h#L476
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-28 16:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 8:56 [PATCH] ACPI: pci: Release excess memory usage Zhe Qiao
2025-04-28 16:35 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).