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@xxxxxxxxxx> --- src/conf/domain_addr.c | 2 +- src/conf/domain_addr.h | 2 +- src/qemu/qemu_domain_address.c | 7 ++----- src/qemu/qemu_hotplug.c | 10 +++------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index 642268239..a44f96470 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -2177,7 +2177,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; diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h index 173101465..7565322bd 100644 --- a/src/conf/domain_addr.h +++ b/src/conf/domain_addr.h @@ -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__ */ diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index e28119e4b..613a27ef5 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2918,11 +2918,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)); } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index c9868de77..27bda3db1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2253,7 +2253,6 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv = vm->privateData; char *devstr = NULL; - bool releaseaddr = false; bool added = false; bool teardowncgroup = false; bool teardownlabel = false; @@ -2262,8 +2261,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) @@ -2316,8 +2314,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; @@ -3818,8 +3815,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; -- 2.13.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list