usb: usbip tool: Fix parse_status()
authorYuyang Du <yuyang.du@intel.com>
Mon, 22 May 2017 10:20:18 +0000 (18:20 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Jun 2017 08:48:24 +0000 (10:48 +0200)
In parse_status(), all nports number of idev's are initiated to
0 by memset(), it is simply wrong, because parse_status() reads
the status sys file one by one, therefore, it can only update the
according vhci_driver->idev's for it to parse.

Reviewed-by: Krzysztof Opasiak <k.opasiak@samsung.com>
Signed-off-by: Yuyang Du <yuyang.du@intel.com>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
tools/usb/usbip/libsrc/vhci_driver.c
tools/usb/usbip/src/usbip_attach.c

index aa82c4b17797b2410d6d2d460a9a6f22ecd3e6b9..f519c73c6d996a43ab1bd24fc4e8696d23f85345 100644 (file)
@@ -36,18 +36,11 @@ err:
        return NULL;
 }
 
-
-
 static int parse_status(const char *value)
 {
        int ret = 0;
        char *c;
 
-
-       for (int i = 0; i < vhci_driver->nports; i++)
-               memset(&vhci_driver->idev[i], 0, sizeof(vhci_driver->idev[i]));
-
-
        /* skip a header line */
        c = strchr(value, '\n');
        if (!c)
@@ -58,6 +51,7 @@ static int parse_status(const char *value)
                int port, status, speed, devid;
                unsigned long socket;
                char lbusid[SYSFS_BUS_ID_SIZE];
+               struct usbip_imported_device *idev;
 
                ret = sscanf(c, "%d %d %d %x %lx %31s\n",
                                &port, &status, &speed,
@@ -72,30 +66,28 @@ static int parse_status(const char *value)
                                port, status, speed, devid);
                dbg("socket %lx lbusid %s", socket, lbusid);
 
-
                /* if a device is connected, look at it */
-               {
-                       struct usbip_imported_device *idev = &vhci_driver->idev[port];
+               idev = &vhci_driver->idev[port];
 
-                       idev->port      = port;
-                       idev->status    = status;
+               memset(idev, 0, sizeof(*idev));
 
-                       idev->devid     = devid;
+               idev->port      = port;
+               idev->status    = status;
 
-                       idev->busnum    = (devid >> 16);
-                       idev->devnum    = (devid & 0x0000ffff);
+               idev->devid     = devid;
 
-                       if (idev->status != VDEV_ST_NULL
-                           && idev->status != VDEV_ST_NOTASSIGNED) {
-                               idev = imported_device_init(idev, lbusid);
-                               if (!idev) {
-                                       dbg("imported_device_init failed");
-                                       return -1;
-                               }
+               idev->busnum    = (devid >> 16);
+               idev->devnum    = (devid & 0x0000ffff);
+
+               if (idev->status != VDEV_ST_NULL
+                   && idev->status != VDEV_ST_NOTASSIGNED) {
+                       idev = imported_device_init(idev, lbusid);
+                       if (!idev) {
+                               dbg("imported_device_init failed");
+                               return -1;
                        }
                }
 
-
                /* go to the next line */
                c = strchr(c, '\n');
                if (!c)
index 70a6b507fb62950ebfc5b500b1b49240f56702ce..62a297ff647ad365f34e8e667ca2a235ae9c8d1a 100644 (file)
@@ -108,6 +108,8 @@ static int import_device(int sockfd, struct usbip_usb_device *udev)
                return -1;
        }
 
+       dbg("got free port %d", port);
+
        rc = usbip_vhci_attach_device(port, sockfd, udev->busnum,
                                      udev->devnum, udev->speed);
        if (rc < 0) {