conf,qemu: Check for NULL addrs in virDomainUSBAddressEnsure

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@redhat.com>
This commit is contained in:
John Ferlan 2017-10-20 07:28:21 -04:00
parent 207cece6a3
commit c6d483cdc5
3 changed files with 12 additions and 16 deletions

View File

@ -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))) {

View File

@ -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,

View File

@ -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)