From b52fa0ea45bea494a953dd766151d584a28e87e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 1 Feb 2021 16:37:00 +0100 Subject: [PATCH] hw/pci: Have safer pcie_bus_realize() by checking error path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Reported-by: Markus Armbruster Signed-off-by: Philippe Mathieu-Daudé Message-Id: <20210201153700.618946-1-philmd@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/pci/pci.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index fa97a671d1..0eadcdbc9e 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -132,8 +132,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