summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drivers/usb/usbip/vhci_sysfs.c6
-rw-r--r--tools/usb/usbip/src/usbip_attach.c35
2 files changed, 25 insertions, 16 deletions
diff --git a/drivers/usb/usbip/vhci_sysfs.c b/drivers/usb/usbip/vhci_sysfs.c
index 5778b640ba9c..1b9f60a22e0b 100644
--- a/drivers/usb/usbip/vhci_sysfs.c
+++ b/drivers/usb/usbip/vhci_sysfs.c
@@ -366,7 +366,11 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
sockfd_put(socket);
dev_err(dev, "port %d already used\n", rhport);
- return -EINVAL;
+ /*
+ * Will be retried from userspace
+ * if there's another free port.
+ */
+ return -EBUSY;
}
dev_info(dev, "pdev(%u) rhport(%u) sockfd(%d)\n",
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)