diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index d783ecc7cb33be8aede782bf8dbfd8d852bb68a7..5e875a3e6ec4119f8f628969d6627d91bec19da2 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -2152,6 +2152,9 @@ int virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs, virDomainDeviceInfoPtr info) { + if (!addrs) + return 0; + if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE || (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB && !virDomainUSBAddressPortIsValid(info->addr.usb.port))) { diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 7565322bd21866b1dfd3ae7f257e1b5948a7b6eb..d3541bab09a28abb2e1f4952fd9c2c9a7478e679 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -325,7 +325,7 @@ virDomainUSBAddressAssign(virDomainUSBAddressSetPtr addrs, int virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs, virDomainDeviceInfoPtr info) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + ATTRIBUTE_NONNULL(2); int virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5cb483f03013930eb384c8f9f984262d7206f880..87cf578acce3482035a55230a6be4556aaf56012 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -677,10 +677,8 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv = vm->privateData; - if (priv->usbaddrs) { - if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0) - return -1; - } + if (virDomainUSBAddressEnsure(priv->usbaddrs, &disk->info) < 0) + return -1; if (qemuDomainAttachDiskGeneric(driver, vm, disk) < 0) { virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); @@ -1827,8 +1825,7 @@ qemuDomainAttachChrDeviceAssignAddr(virDomainObjPtr vm, return -1; return 1; - } else if (priv->usbaddrs && - chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && + } else if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && chr->targetType == VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_USB) { if (virDomainUSBAddressEnsure(priv->usbaddrs, &chr->info) < 0) return -1; @@ -2247,10 +2244,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, bool teardowndevice = false; int ret = -1; - if (priv->usbaddrs) { - if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) - return -1; - } + if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0) + return -1; if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0) goto cleanup; @@ -2840,11 +2835,9 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver, if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, "input") < 0) return -1; } else if (input->bus == VIR_DOMAIN_INPUT_BUS_USB) { - if (priv->usbaddrs) { - if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0) - goto cleanup; - releaseaddr = true; - } + if (virDomainUSBAddressEnsure(priv->usbaddrs, &input->info) < 0) + goto cleanup; + releaseaddr = true; } if (qemuAssignDeviceInputAlias(vm->def, input, -1) < 0)