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

Michal Privoznik mprivozn at redhat.com
Tue Jun 18 13:04:25 UTC 2019


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 at redhat.com>
---
 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




More information about the libvir-list mailing list