Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_addr.c | 3 +++
src/conf/domain_addr.h | 2 +-
src/qemu/qemu_hotplug.c | 23 ++++++++---------------
3 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index a44f964701..78ff7a9cc6 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -2154,6 +2154,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 7565322bd2..d3541bab09 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 10cdba436b..51a7a68f84 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -664,10 +664,8 @@ qemuDomainAttachUSBMassStorageDevice(virConnectPtr conn,
{
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(conn, driver, vm, disk) < 0) {
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
@@ -1772,8 +1770,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;
@@ -2187,10 +2184,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;
@@ -2750,11 +2745,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)
--
2.13.6