Rather than having the caller check, if the input @addrs is NULL
(e.g. priv->usbaddrs), then just return 0. This also removes the
need for ATTRIBUTE_NONNULL which only really helped if someone
passed a NULL as a parameter not if the passed parameter is NULL.
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 a44f96470..78ff7a9cc 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 7565322bd..d3541bab0 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 27bda3db1..57fa035b8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -681,10 +681,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);
@@ -1837,8 +1835,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;
@@ -2259,10 +2256,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;
@@ -2854,11 +2849,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