conf,qemu: Check for NULL addrs in virDomainUSBAddressRelease

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:24:49 -04:00
parent 9c61c28081
commit 207cece6a3
4 changed files with 7 additions and 14 deletions

View File

@ -2175,7 +2175,7 @@ virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs,
int targetPort;
int ret = -1;
if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB ||
if (!addrs || info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB ||
!virDomainUSBAddressPortIsValid(info->addr.usb.port))
return 0;

View File

@ -330,5 +330,5 @@ virDomainUSBAddressEnsure(virDomainUSBAddressSetPtr addrs,
int
virDomainUSBAddressRelease(virDomainUSBAddressSetPtr addrs,
virDomainDeviceInfoPtr info)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
ATTRIBUTE_NONNULL(2);
#endif /* __DOMAIN_ADDR_H__ */

View File

@ -2943,11 +2943,8 @@ qemuDomainReleaseDeviceAddress(virDomainObjPtr vm,
if (virDeviceInfoPCIAddressPresent(info))
virDomainPCIAddressReleaseAddr(priv->pciaddrs, &info->addr.pci);
if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB &&
priv->usbaddrs &&
virDomainUSBAddressRelease(priv->usbaddrs, info) < 0)
VIR_WARN("Unable to release USB address on %s",
NULLSTR(devstr));
if (virDomainUSBAddressRelease(priv->usbaddrs, info) < 0)
VIR_WARN("Unable to release USB address on %s", NULLSTR(devstr));
}

View File

@ -2241,7 +2241,6 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
{
qemuDomainObjPrivatePtr priv = vm->privateData;
char *devstr = NULL;
bool releaseaddr = false;
bool added = false;
bool teardowncgroup = false;
bool teardownlabel = false;
@ -2250,8 +2249,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
if (priv->usbaddrs) {
if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
goto cleanup;
releaseaddr = true;
return -1;
}
if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0)
@ -2304,8 +2302,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
VIR_WARN("Unable to remove host device from /dev");
if (added)
qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
if (releaseaddr)
virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
}
VIR_FREE(devstr);
return ret;
@ -3827,8 +3824,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
dev.type = VIR_DOMAIN_DEVICE_DISK;
dev.data.disk = disk;
ignore_value(qemuRemoveSharedDevice(driver, &dev, vm->def->name));
if (priv->usbaddrs)
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
virDomainUSBAddressRelease(priv->usbaddrs, &disk->info);
virDomainDiskDefFree(disk);
return 0;