hw/pci-host/i440fx: handle NULL bus in pci-hole64 getters
When called on an unrealized i440FX 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 pci_hole64_start and pci_hole64_end getters, reporting an error. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Marc-André Lureau committed
Apr 24, 2026 at 19:04 UTC
9279ddf2eb34de9da54ab78868768fe37647f336
1 file changed
+13
-2
hw/pci-host/i440fx.c
+13
-2
@@ -189,8 +189,14 @@ static void i440fx_pcihost_get_pci_hole64_start(Object *obj, Visitor *v,
189
const char *name,
190
void *opaque, Error **errp)
191
{
192
- uint64_t hole64_start = i440fx_pcihost_get_pci_hole64_start_value(obj);
192
+ PCIHostState *h = PCI_HOST_BRIDGE(obj);
193
+ uint64_t hole64_start;
194
195
+ if (!h->bus) {
196
+ error_setg(errp, "PCI host bridge not realized");
197
+ return;
198
+ }
199
+ hole64_start = i440fx_pcihost_get_pci_hole64_start_value(obj);
200
visit_type_uint64(v, name, &hole64_start, errp);
201
}
202
@@ -206,10 +212,15 @@ static void i440fx_pcihost_get_pci_hole64_end(Object *obj, Visitor *v,
212
{
213
PCIHostState *h = PCI_HOST_BRIDGE(obj);
214
I440FXState *s = I440FX_PCI_HOST_BRIDGE(obj);
209
- uint64_t hole64_start = i440fx_pcihost_get_pci_hole64_start_value(obj);
215
+ uint64_t hole64_start;
216
Range w64;
217
uint64_t value, hole64_end;
218
219
+ if (!h->bus) {
220
+ error_setg(errp, "PCI host bridge not realized");
221
+ return;
222
+ }
223
+ hole64_start = i440fx_pcihost_get_pci_hole64_start_value(obj);
224
pci_bus_get_w64_range(h->bus, &w64);
225
value = range_is_empty(&w64) ? 0 : range_upb(&w64) + 1;
226
hole64_end = ROUND_UP(hole64_start + s->pci_hole64_size, 1ULL << 30);