* [PATCH v2] ACPI: PCI: Release excess memory usage.
@ 2025-04-29 9:10 Zhe Qiao
2025-04-29 13:20 ` Jonathan Cameron
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zhe Qiao @ 2025-04-29 9:10 UTC (permalink / raw)
To: rafael, lenb, bhelgaas, will, sunilvl, qiaozhe
Cc: linux-acpi, linux-pci, linux-kernel
In the pci_acpi_scan_root() function, if the PCI bus creation failed,
the allocated memory should be released to avoid memory occupation.
Fixes: 789befdfa389 ("arm64: PCI: Migrate ACPI related functions to pci-acpi.c")
Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>
---
V1 -> V2:
Modified labels for better readability.
---
drivers/pci/pci-acpi.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index af370628e583..bde104ecac80 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1677,15 +1677,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
if (!root_ops) {
- kfree(ri);
- return NULL;
+ goto free_ri;
}
ri->cfg = pci_acpi_setup_ecam_mapping(root);
if (!ri->cfg) {
- kfree(ri);
- kfree(root_ops);
- return NULL;
+ goto free_root_ops;
}
root_ops->release_info = pci_acpi_generic_release_info;
@@ -1693,7 +1690,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 free_root_ops;
/* If we must preserve the resource configuration, claim now */
host = pci_find_host_bridge(bus);
@@ -1710,6 +1707,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
pcie_bus_configure_settings(child);
return bus;
+
+free_root_ops:
+ kfree(root_ops);
+free_ri:
+ kfree(ri);
+ return NULL;
}
void pcibios_add_bus(struct pci_bus *bus)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] ACPI: PCI: Release excess memory usage.
2025-04-29 9:10 [PATCH v2] ACPI: PCI: Release excess memory usage Zhe Qiao
@ 2025-04-29 13:20 ` Jonathan Cameron
2025-04-29 15:46 ` Markus Elfring
2025-04-29 15:56 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2025-04-29 13:20 UTC (permalink / raw)
To: Zhe Qiao
Cc: rafael, lenb, bhelgaas, will, sunilvl, linux-acpi, linux-pci,
linux-kernel
On Tue, 29 Apr 2025 17:10:51 +0800
Zhe Qiao <qiaozhe@iscas.ac.cn> wrote:
> In the pci_acpi_scan_root() function, if the PCI bus creation failed,
> the allocated memory should be released to avoid memory occupation.
>
> Fixes: 789befdfa389 ("arm64: PCI: Migrate ACPI related functions to pci-acpi.c")
> Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>
>
> ---
> V1 -> V2:
> Modified labels for better readability.
>
> ---
> drivers/pci/pci-acpi.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
> index af370628e583..bde104ecac80 100644
> --- a/drivers/pci/pci-acpi.c
> +++ b/drivers/pci/pci-acpi.c
> @@ -1677,15 +1677,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>
> root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
> if (!root_ops) {
> - kfree(ri);
> - return NULL;
> + goto free_ri;
> }
>
> ri->cfg = pci_acpi_setup_ecam_mapping(root);
> if (!ri->cfg) {
> - kfree(ri);
> - kfree(root_ops);
> - return NULL;
> + goto free_root_ops;
> }
>
> root_ops->release_info = pci_acpi_generic_release_info;
> @@ -1693,7 +1690,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;
Do we also need to tear down the ecam mapping done in pci_acpi_setup_ecam_mapping()?
Might just be pci_ecam_free(ri->cfg);
> + goto free_root_ops;
>
> /* If we must preserve the resource configuration, claim now */
> host = pci_find_host_bridge(bus);
> @@ -1710,6 +1707,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
> pcie_bus_configure_settings(child);
>
> return bus;
> +
> +free_root_ops:
> + kfree(root_ops);
> +free_ri:
> + kfree(ri);
> + return NULL;
> }
>
> void pcibios_add_bus(struct pci_bus *bus)
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] ACPI: PCI: Release excess memory usage.
2025-04-29 9:10 [PATCH v2] ACPI: PCI: Release excess memory usage Zhe Qiao
2025-04-29 13:20 ` Jonathan Cameron
@ 2025-04-29 15:46 ` Markus Elfring
2025-04-29 15:56 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-04-29 15:46 UTC (permalink / raw)
To: Zhe Qiao, linux-acpi, linux-pci
Cc: LKML, Bjorn Helgaas, Jonathan Cameron, Len Brown,
Rafael J. Wysocki, Sunil V L, Will Deacon
…
> the allocated memory should be released to avoid memory occupation.
Will an imperative wording be more desirable for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.15-rc4#n94
Do you propose to complete the exception handling?
How will development interests grow for 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] 4+ messages in thread
* Re: [PATCH v2] ACPI: PCI: Release excess memory usage
2025-04-29 9:10 [PATCH v2] ACPI: PCI: Release excess memory usage Zhe Qiao
2025-04-29 13:20 ` Jonathan Cameron
2025-04-29 15:46 ` Markus Elfring
@ 2025-04-29 15:56 ` Markus Elfring
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-04-29 15:56 UTC (permalink / raw)
To: Zhe Qiao, linux-acpi, linux-pci
Cc: LKML, Bjorn Helgaas, Jonathan Cameron, Len Brown,
Rafael J. Wysocki, Sunil V L, Will Deacon
…
> +++ b/drivers/pci/pci-acpi.c
> @@ -1677,15 +1677,12 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>
> root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
> if (!root_ops) {
> - kfree(ri);
> - return NULL;
> + goto free_ri;
> }
Would you like to omit curly brackets around a single statement?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.15-rc4#n197
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-04-29 15:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-29 9:10 [PATCH v2] ACPI: PCI: Release excess memory usage Zhe Qiao
2025-04-29 13:20 ` Jonathan Cameron
2025-04-29 15:46 ` Markus Elfring
2025-04-29 15:56 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox