mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] ACPI: PCI: Release excess memory usage.
@ 2025-04-30  6:06 Zhe Qiao
  2025-05-09 18:50 ` Rafael J. Wysocki
  2025-05-22 11:04 ` Krzysztof Wilczyński
  0 siblings, 2 replies; 3+ messages in thread
From: Zhe Qiao @ 2025-04-30  6:06 UTC (permalink / raw)
  To: rafael, lenb, bhelgaas, will, sunilvl, Markus.Elfring, qiaozhe
  Cc: linux-acpi, linux-pci, linux-kernel

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: 789befdfa389 ("arm64: PCI: Migrate ACPI related functions to pci-acpi.c")
Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>

---
V2 -> V3
    1. Modify commit description.
    2. Add release operation for ecam mapping resources.
---

 drivers/pci/pci-acpi.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
index af370628e583..e00790ecdc0f 100644
--- a/drivers/pci/pci-acpi.c
+++ b/drivers/pci/pci-acpi.c
@@ -1676,24 +1676,19 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
 		return NULL;
 
 	root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
-	if (!root_ops) {
-		kfree(ri);
-		return NULL;
-	}
+	if (!root_ops)
+		goto free_ri;
 
 	ri->cfg = pci_acpi_setup_ecam_mapping(root);
-	if (!ri->cfg) {
-		kfree(ri);
-		kfree(root_ops);
-		return NULL;
-	}
+	if (!ri->cfg)
+		goto free_root_ops;
 
 	root_ops->release_info = pci_acpi_generic_release_info;
 	root_ops->prepare_resources = pci_acpi_root_prepare_resources;
 	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_cfg;
 
 	/* If we must preserve the resource configuration, claim now */
 	host = pci_find_host_bridge(bus);
@@ -1710,6 +1705,14 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
 		pcie_bus_configure_settings(child);
 
 	return bus;
+
+free_cfg:
+	pci_ecam_free(ri->cfg);
+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	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ACPI: PCI: Release excess memory usage.
  2025-04-30  6:06 [PATCH v3] ACPI: PCI: Release excess memory usage Zhe Qiao
@ 2025-05-09 18:50 ` Rafael J. Wysocki
  2025-05-22 11:04 ` Krzysztof Wilczyński
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2025-05-09 18:50 UTC (permalink / raw)
  To: Zhe Qiao
  Cc: rafael, lenb, bhelgaas, will, sunilvl, Markus.Elfring,
	linux-acpi, linux-pci, linux-kernel

On Wed, Apr 30, 2025 at 8:06 AM Zhe Qiao <qiaozhe@iscas.ac.cn> wrote:
>
> 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: 789befdfa389 ("arm64: PCI: Migrate ACPI related functions to pci-acpi.c")
> Signed-off-by: Zhe Qiao <qiaozhe@iscas.ac.cn>

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

and I'm expecting this to go in via PCI.

> ---
> V2 -> V3
>     1. Modify commit description.
>     2. Add release operation for ecam mapping resources.
> ---
>
>  drivers/pci/pci-acpi.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c
> index af370628e583..e00790ecdc0f 100644
> --- a/drivers/pci/pci-acpi.c
> +++ b/drivers/pci/pci-acpi.c
> @@ -1676,24 +1676,19 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>                 return NULL;
>
>         root_ops = kzalloc(sizeof(*root_ops), GFP_KERNEL);
> -       if (!root_ops) {
> -               kfree(ri);
> -               return NULL;
> -       }
> +       if (!root_ops)
> +               goto free_ri;
>
>         ri->cfg = pci_acpi_setup_ecam_mapping(root);
> -       if (!ri->cfg) {
> -               kfree(ri);
> -               kfree(root_ops);
> -               return NULL;
> -       }
> +       if (!ri->cfg)
> +               goto free_root_ops;
>
>         root_ops->release_info = pci_acpi_generic_release_info;
>         root_ops->prepare_resources = pci_acpi_root_prepare_resources;
>         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_cfg;
>
>         /* If we must preserve the resource configuration, claim now */
>         host = pci_find_host_bridge(bus);
> @@ -1710,6 +1705,14 @@ struct pci_bus *pci_acpi_scan_root(struct acpi_pci_root *root)
>                 pcie_bus_configure_settings(child);
>
>         return bus;
> +
> +free_cfg:
> +       pci_ecam_free(ri->cfg);
> +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	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] ACPI: PCI: Release excess memory usage.
  2025-04-30  6:06 [PATCH v3] ACPI: PCI: Release excess memory usage Zhe Qiao
  2025-05-09 18:50 ` Rafael J. Wysocki
@ 2025-05-22 11:04 ` Krzysztof Wilczyński
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Wilczyński @ 2025-05-22 11:04 UTC (permalink / raw)
  To: rafael, lenb, bhelgaas, will, sunilvl, Markus.Elfring, Zhe Qiao
  Cc: linux-acpi, linux-pci, linux-kernel

Hello,

> 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.

Applied to pci-acpi, thank you!

[1/1] ACPI: PCI: Release excess memory usage.
      https://git.kernel.org/pci/pci/c/631b2af2f357

	Krzysztof

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-05-22 11:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-30  6:06 [PATCH v3] ACPI: PCI: Release excess memory usage Zhe Qiao
2025-05-09 18:50 ` Rafael J. Wysocki
2025-05-22 11:04 ` Krzysztof Wilczyński

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®