[SeaBIOS] [PATCH 1/2] fw/pciinit: factor out pci resource allocation

Abhimanyu Saini via SeaBIOS posted 2 patches 2 months ago
[SeaBIOS] [PATCH 1/2] fw/pciinit: factor out pci resource allocation
Posted by Abhimanyu Saini via SeaBIOS 2 months ago
Factor out PCI resource allocation code to a separate
function. This makes it easier to follow, and paves
the way to support skipping this step when instructed
by the platform (in a followup patch).

While at it, fix the leak of *busses in case
pci_bios_check_devices fails.

Signed-off-by: Abhimanyu Saini <sainiabr@amazon.de>
---
 src/fw/pciinit.c | 35 +++++++++++++++++++++--------------
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
index b3e359d7..334fd30c 100644
--- a/src/fw/pciinit.c
+++ b/src/fw/pciinit.c
@@ -1174,6 +1174,26 @@ static void pci_bios_map_devices(struct pci_bus *busses)
     }
 }
 
+static void pci_allocate_resources(void)
+{
+    struct pci_bus *busses;
+
+    dprintf(1, "=== PCI new allocation pass #1 ===\n");
+    busses = malloc_tmp(sizeof(*busses) * (MaxPCIBus + 1));
+    if (!busses) {
+        warn_noalloc();
+        return;
+    }
+    memset(busses, 0, sizeof(*busses) * (MaxPCIBus + 1));
+    if (pci_bios_check_devices(busses))
+        goto cleanup;
+
+    dprintf(1, "=== PCI new allocation pass #2 ===\n");
+    pci_bios_map_devices(busses);
+
+cleanup:
+    free(busses);
+}
 
 /****************************************************************
  * Main setup code
@@ -1217,22 +1237,9 @@ pci_setup(void)
     pcimem_start = RamSize;
     pci_bios_init_platform();
 
-    dprintf(1, "=== PCI new allocation pass #1 ===\n");
-    struct pci_bus *busses = malloc_tmp(sizeof(*busses) * (MaxPCIBus + 1));
-    if (!busses) {
-        warn_noalloc();
-        return;
-    }
-    memset(busses, 0, sizeof(*busses) * (MaxPCIBus + 1));
-    if (pci_bios_check_devices(busses))
-        return;
-
-    dprintf(1, "=== PCI new allocation pass #2 ===\n");
-    pci_bios_map_devices(busses);
+    pci_allocate_resources();
 
     pci_bios_init_devices();
 
-    free(busses);
-
     pci_enable_default_vga();
 }
-- 
2.40.1




Amazon Web Services Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B
Sitz: Berlin
Ust-ID: DE 365 538 597

_______________________________________________
SeaBIOS mailing list -- seabios@seabios.org
To unsubscribe send an email to seabios-leave@seabios.org