@samitouri / QOSamiQemu / commits / 9817094a1e

hw/pci-host/q35: handle NULL bus in pci-hole64 getters

When called on an unrealized Q35 host bridge (e.g. from qmp_qom_list_properties), h->bus is NULL since the root bus is only created during realize. Guard against this in both the pci_hole64_start and pci_hole64_end getters. 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 9817094a1e18bc8672279a0cc4dd26f7fc23527e
1 file changed +13 -2
hw/pci-host/q35.c
+13 -2
@@ -132,8 +132,14 @@ static void q35_host_get_pci_hole64_start(Object *obj, Visitor *v,
132 const char *name, void *opaque,
133 Error **errp)
134 {
135 - uint64_t hole64_start = q35_host_get_pci_hole64_start_value(obj);
135 + PCIHostState *h = PCI_HOST_BRIDGE(obj);
136 + uint64_t hole64_start;
137
138 + if (!h->bus) {
139 + error_setg(errp, "PCI host bridge not realized");
140 + return;
141 + }
142 + hole64_start = q35_host_get_pci_hole64_start_value(obj);
143 visit_type_uint64(v, name, &hole64_start, errp);
144 }
145
@@ -149,10 +155,15 @@ static void q35_host_get_pci_hole64_end(Object *obj, Visitor *v,
155 {
156 PCIHostState *h = PCI_HOST_BRIDGE(obj);
157 Q35PCIHost *s = Q35_HOST_DEVICE(obj);
152 - uint64_t hole64_start = q35_host_get_pci_hole64_start_value(obj);
158 + uint64_t hole64_start;
159 Range w64;
160 uint64_t value, hole64_end;
161
162 + if (!h->bus) {
163 + error_setg(errp, "PCI host bridge not realized");
164 + return;
165 + }
166 + hole64_start = q35_host_get_pci_hole64_start_value(obj);
167 pci_bus_get_w64_range(h->bus, &w64);
168 value = range_is_empty(&w64) ? 0 : range_upb(&w64) + 1;
169 hole64_end = ROUND_UP(hole64_start + s->mch.pci_hole64_size, 1ULL << 30);