Instances allocated on the stack or using VIR_ALLOC() directly skip the initialization process. Use the proper allocation function instead to ensure all virDomainDeviceInfo instances are properly initialized. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- src/conf/domain_addr.c | 6 ++++-- src/conf/domain_conf.c | 4 ++-- src/libvirt_private.syms | 2 ++ src/qemu/qemu_domain_address.c | 29 +++++++++++++++++------------ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 639168e..0c6e8c3 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1427,8 +1427,8 @@ virDomainVirtioSerialAddrAssign(virDomainDefPtr def, bool portOnly) { int ret = -1; - virDomainDeviceInfo nfo = { NULL }; - virDomainDeviceInfoPtr ptr = allowZero ? &nfo : info; + virDomainDeviceInfoPtr nfo = virDomainDeviceInfoNew(); + virDomainDeviceInfoPtr ptr = allowZero ? nfo : info; ptr->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL; @@ -1448,6 +1448,8 @@ virDomainVirtioSerialAddrAssign(virDomainDefPtr def, ret = 0; cleanup: + virDomainDeviceInfoFree(nfo); + return ret; } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6a89fab..11c4627 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2364,7 +2364,7 @@ virDomainHostdevDefNew(virDomainXMLOptionPtr xmlopt) if (VIR_ALLOC(def) < 0) return NULL; - if (VIR_ALLOC(def->info) < 0) + if (!(def->info = virDomainDeviceInfoNew())) goto error; if (xmlopt && @@ -2376,7 +2376,7 @@ virDomainHostdevDefNew(virDomainXMLOptionPtr xmlopt) return def; error: - VIR_FREE(def->info); + virDomainDeviceInfoFree(def->info); VIR_FREE(def); goto cleanup; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 178aefc..48e9e33 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -91,6 +91,8 @@ virCPUModeTypeToString; # conf/device_conf.h virDomainDeviceInfoAddressIsEqual; virDomainDeviceInfoCopy; +virDomainDeviceInfoFree; +virDomainDeviceInfoNew; virInterfaceLinkFormat; virInterfaceLinkParseXML; virPCIDeviceAddressEqual; diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index b5b863f..93ab304 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -1983,6 +1983,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, int ret = -1; virDomainPCIAddressSetPtr addrs = NULL; qemuDomainObjPrivatePtr priv = NULL; + virDomainDeviceInfoPtr info = virDomainDeviceInfoNew(); int max_idx = -1; int nbuses = 0; size_t i; @@ -2031,16 +2032,15 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, */ if (qemuDomainHasPCIRoot(def)) { - /* This is a dummy info used to reserve a slot for a + bool buses_reserved = true; + + /* The dummy info is used to reserve a slot for a * legacy PCI device that doesn't exist, but may in the * future, e.g. if another device is hotplugged into the * domain. */ - virDomainDeviceInfo info = { - .pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE | - VIR_PCI_CONNECT_TYPE_PCI_DEVICE) - }; - bool buses_reserved = true; + info->pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE | + VIR_PCI_CONNECT_TYPE_PCI_DEVICE); for (i = 0; i < addrs->nbuses; i++) { if (!qemuDomainPCIBusFullyReserved(&addrs->buses[i])) { @@ -2049,7 +2049,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, } } if (!buses_reserved && - qemuDomainPCIAddressReserveNextAddr(addrs, &info) < 0) + qemuDomainPCIAddressReserveNextAddr(addrs, info) < 0) goto cleanup; } @@ -2073,15 +2073,19 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, if (max_idx <= 0 && addrs->nbuses > max_idx + 1 && qemuDomainHasPCIeRoot(def)) { - virDomainDeviceInfo info = { - .pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE | - VIR_PCI_CONNECT_TYPE_PCIE_DEVICE) - }; + + /* The dummy info is used to reserve a slot for a + * PCI Express device that doesn't exist, but may in the + * future, e.g. if another device is hotplugged into the + * domain. + */ + info->pciConnectFlags = (VIR_PCI_CONNECT_HOTPLUGGABLE | + VIR_PCI_CONNECT_TYPE_PCIE_DEVICE); /* if there isn't an empty pcie-root-port, this will * cause one to be added */ - if (qemuDomainPCIAddressReserveNextAddr(addrs, &info) < 0) + if (qemuDomainPCIAddressReserveNextAddr(addrs, info) < 0) goto cleanup; } @@ -2234,6 +2238,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def, ret = 0; cleanup: + virDomainDeviceInfoFree(info); virDomainPCIAddressSetFree(addrs); return ret; -- 2.7.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list