hw/pci-bridge: handle missing parent in prop_pxb_uid_get
When called on an unrealized pxb bus (e.g. from qmp_qom_list_properties), bus->parent_dev is NULL. The pxb_bus_num() callback dereferences it unconditionally. Check for this to avoid a NULL dereference. Fixes: 97b9cb066e5f ("hw/pci-bridge: Add acpi_uid property to TYPE_PXB_BUS") Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Apr 24, 2026 at 19:04 UTC
ce2e8408a14a35f4ec634d80ca65dfe5129814a9
1 file changed
+7
-1
hw/pci-bridge/pci_expander_bridge.c
+7
-1
@@ -85,8 +85,14 @@ static uint16_t pxb_bus_numa_node(PCIBus *bus)
85
static void prop_pxb_uid_get(Object *obj, Visitor *v, const char *name,
86
void *opaque, Error **errp)
87
{
88
- uint32_t uid = pci_bus_num(PCI_BUS(obj));
88
+ PCIBus *bus = PCI_BUS(obj);
89
+ uint32_t uid;
90
91
+ if (!bus->parent_dev) {
92
+ error_setg(errp, "bus not attached to a device");
93
+ return;
94
+ }
95
+ uid = pci_bus_num(bus);
96
visit_type_uint32(v, name, &uid, errp);
97
}
98