virHostdevFindUSBDevice: Simplify flow a bit

When looking up a USB device by vendor the
virUSBDeviceFindByVendor() is used. The function returns number
of items found. But the logic in caller to process it is
needlessly complicated.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2019-06-15 09:22:12 +02:00
parent f08e6883cb
commit 35d61939bc

View File

@ -1400,15 +1400,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
VIR_AUTOUNREF(virUSBDeviceListPtr) devs = NULL;
rc = virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, &devs);
if (rc < 0)
if (rc < 0) {
return -1;
if (rc == 1) {
*usb = virUSBDeviceListGet(devs, 0);
virUSBDeviceListSteal(devs, *usb);
}
if (rc == 0) {
} else if (rc == 0) {
goto out;
} else if (rc > 1) {
if (autoAddress) {
@ -1425,6 +1419,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
return -1;
}
*usb = virUSBDeviceListGet(devs, 0);
virUSBDeviceListSteal(devs, *usb);
usbsrc->bus = virUSBDeviceGetBus(*usb);
usbsrc->device = virUSBDeviceGetDevno(*usb);
usbsrc->autoAddress = true;