|
@@ -99,29 +99,34 @@ static int import_device(int sockfd, struct usbip_usb_device *udev)
|
|
|
rc = usbip_vhci_driver_open();
|
|
|
if (rc < 0) {
|
|
|
err("open vhci_driver");
|
|
|
- return -1;
|
|
|
+ goto err_out;
|
|
|
}
|
|
|
|
|
|
- port = usbip_vhci_get_free_port(speed);
|
|
|
- if (port < 0) {
|
|
|
- err("no free port");
|
|
|
- usbip_vhci_driver_close();
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ do {
|
|
|
+ port = usbip_vhci_get_free_port(speed);
|
|
|
+ if (port < 0) {
|
|
|
+ err("no free port");
|
|
|
+ goto err_driver_close;
|
|
|
+ }
|
|
|
|
|
|
- dbg("got free port %d", port);
|
|
|
+ dbg("got free port %d", port);
|
|
|
|
|
|
- rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
|
|
|
- udev->devnum, udev->speed);
|
|
|
- if (rc < 0) {
|
|
|
- err("import device");
|
|
|
- usbip_vhci_driver_close();
|
|
|
- return -1;
|
|
|
- }
|
|
|
+ rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
|
|
|
+ udev->devnum, udev->speed);
|
|
|
+ if (rc < 0 && errno != EBUSY) {
|
|
|
+ err("import device");
|
|
|
+ goto err_driver_close;
|
|
|
+ }
|
|
|
+ } while (rc < 0);
|
|
|
|
|
|
usbip_vhci_driver_close();
|
|
|
|
|
|
return port;
|
|
|
+
|
|
|
+err_driver_close:
|
|
|
+ usbip_vhci_driver_close();
|
|
|
+err_out:
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
static int query_import_device(int sockfd, char *busid)
|