diff options
Diffstat (limited to 'tools/usb/usbip/src/usbip_attach.c')
-rw-r--r-- | tools/usb/usbip/src/usbip_attach.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/tools/usb/usbip/src/usbip_attach.c b/tools/usb/usbip/src/usbip_attach.c index 6e89768ffe30..7f07b2d50f59 100644 --- a/tools/usb/usbip/src/usbip_attach.c +++ b/tools/usb/usbip/src/usbip_attach.c @@ -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) |