From 35d61939bc3c4df1d447edfae02efd18f838d7c3 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Sat, 15 Jun 2019 09:22:12 +0200 Subject: [PATCH] virHostdevFindUSBDevice: Simplify flow a bit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- 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 29961ace60..29e37ee4db 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -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;