mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:56:38 +00:00
hw/pci: handle missing bus in prop_pci_busnr_get
When called on an unrealized device (e.g. from
qmp_qom_list_properties), pci_get_bus() returns NULL since the device
has no parent bus. Check for this to avoid a NULL dereference in
pci_bus_num().
Fixes: df9ac7254f ("hw/pci: Add a busnr property to pci_props and use for acpi/gi")
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
11
hw/pci/pci.c
11
hw/pci/pci.c
@@ -64,10 +64,17 @@ static void pcibus_reset_hold(Object *obj, ResetType type);
|
||||
static bool pcie_has_upstream_port(PCIDevice *dev);
|
||||
|
||||
static void prop_pci_busnr_get(Object *obj, Visitor *v, const char *name,
|
||||
void *opaque, Error **errp)
|
||||
void *opaque, Error **errp)
|
||||
{
|
||||
uint8_t busnr = pci_dev_bus_num(PCI_DEVICE(obj));
|
||||
PCIDevice *dev = PCI_DEVICE(obj);
|
||||
PCIBus *bus = pci_get_bus(dev);
|
||||
uint8_t busnr;
|
||||
|
||||
if (!bus) {
|
||||
error_setg(errp, "device not attached to a PCI bus");
|
||||
return;
|
||||
}
|
||||
busnr = pci_bus_num(bus);
|
||||
visit_type_uint8(v, name, &busnr, errp);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user