mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 14:45:24 +00:00
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:
parent
f08e6883cb
commit
35d61939bc
@ -1400,15 +1400,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
|
|||||||
VIR_AUTOUNREF(virUSBDeviceListPtr) devs = NULL;
|
VIR_AUTOUNREF(virUSBDeviceListPtr) devs = NULL;
|
||||||
|
|
||||||
rc = virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, &devs);
|
rc = virUSBDeviceFindByVendor(vendor, product, NULL, mandatory, &devs);
|
||||||
if (rc < 0)
|
if (rc < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
} else if (rc == 0) {
|
||||||
if (rc == 1) {
|
|
||||||
*usb = virUSBDeviceListGet(devs, 0);
|
|
||||||
virUSBDeviceListSteal(devs, *usb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc == 0) {
|
|
||||||
goto out;
|
goto out;
|
||||||
} else if (rc > 1) {
|
} else if (rc > 1) {
|
||||||
if (autoAddress) {
|
if (autoAddress) {
|
||||||
@ -1425,6 +1419,9 @@ virHostdevFindUSBDevice(virDomainHostdevDefPtr hostdev,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*usb = virUSBDeviceListGet(devs, 0);
|
||||||
|
virUSBDeviceListSteal(devs, *usb);
|
||||||
|
|
||||||
usbsrc->bus = virUSBDeviceGetBus(*usb);
|
usbsrc->bus = virUSBDeviceGetBus(*usb);
|
||||||
usbsrc->device = virUSBDeviceGetDevno(*usb);
|
usbsrc->device = virUSBDeviceGetDevno(*usb);
|
||||||
usbsrc->autoAddress = true;
|
usbsrc->autoAddress = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user