提交 35d61939 编写于 作者: M Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 f08e6883
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册