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@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 6422682391..a44f964701 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 1731014656..7565322bd2 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 7f4ac0f45a..7d2e2e75d9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -2895,11 +2895,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 91f7f9ed62..10cdba436b 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2181,7 +2181,6 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, { qemuDomainObjPrivatePtr priv = vm->privateData; char *devstr = NULL; - bool releaseaddr = false; bool added = false; bool teardowncgroup = false; bool teardownlabel = false; @@ -2190,8 +2189,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) @@ -2244,8 +2242,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; @@ -3684,8 +3681,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