[PATCH 6/8] virHostdevFindUSBDevice: Simplify flow a bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/util/virhostdev.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 31ad287866..9817c6571b 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1399,15 +1399,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) {
@@ -1424,6 +1418,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
             return -1;
         }
 
+        *usb = virUSBDeviceListGet(devs, 0);
+        virUSBDeviceListSteal(devs, *usb);
+
         usbsrc->bus = virUSBDeviceGetBus(*usb);
         usbsrc->device = virUSBDeviceGetDevno(*usb);
         usbsrc->autoAddress = true;
-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux