Skip to contentSkip to conversation

hw/pci: Have safer pcie_bus_realize() by checking error path

PATCH In review Philippe Mathieu-Daudé 1 participant 2 messages Feb 1, 2021 – Mar 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/pci: Have safer pcie_bus_realize() by checking error path

While pci_bus_realize() currently does not use the Error* argument, it would be an error to leave pcie_bus_realize() setting bus->flags if pci_bus_realize() had failed.

Fix by using a local Error* and return early (propagating the error) if pci_bus_realize() failed.

---
 hw/pci/pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/pci/pci.c +6 -1
index 512e9042ffa..0d12e94a02e 100644
@@ -130,8 +130,13 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
 static void pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
+    Error *local_err = NULL;
 
-    pci_bus_realize(qbus, errp);
+    pci_bus_realize(qbus, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     /*
      * A PCI-E bus can support extended config space if it's the root
Signature · 1 line
2.26.2
#1 lore raw

ping?

Quoted 33 lines · Philippe Mathieu-Daudé

While pci_bus_realize() currently does not use the Error* argument, it would be an error to leave pcie_bus_realize() setting bus->flags if pci_bus_realize() had failed.

Fix by using a local Error* and return early (propagating the error) if pci_bus_realize() failed.

---
 hw/pci/pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/pci/pci.c +6 -1
index 512e9042ffa..0d12e94a02e 100644
@@ -130,8 +130,13 @@ static void pci_bus_realize(BusState *qbus, Error **errp)
 static void pcie_bus_realize(BusState *qbus, Error **errp)
 {
     PCIBus *bus = PCI_BUS(qbus);
+    Error *local_err = NULL;
 
-    pci_bus_realize(qbus, errp);
+    pci_bus_realize(qbus, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
+    }
 
     /*
      * A PCI-E bus can support extended config space if it's the root