]> xenbits.xensource.com Git - libvirt.git/commitdiff
virHostdevFindUSBDevice: Simplify flow a bit
authorMichal Privoznik <mprivozn@redhat.com>
Sat, 15 Jun 2019 07:22:12 +0000 (09:22 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 20 Jun 2019 08:29:54 +0000 (10:29 +0200)
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>
src/util/virhostdev.c

index 29961ace60bb15bfee43ec4cb3e9dff7256f62e9..29e37ee4dbab26d8b9d31015548d84648a0fa741 100644 (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;