aboutsummaryrefslogtreecommitdiffstats
path: root/tools/usb/usbip/libsrc
diff options
context:
space:
mode:
authorYuyang Du <yuyang.du@intel.com>2017-04-05 18:03:23 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-04-08 06:17:42 -0400
commit37e47d5cfeec1dcc8246401ce84f2780f99ce990 (patch)
tree5b77bd129a98f725deed9ddc69149a63cbc301b0 /tools/usb/usbip/libsrc
parent69307ccb9ad7ccb653e332de68effdeaaab6907d (diff)
usb: usbip tool: Fix get_nports()
The commit 0775a9cbc694e8c72 ("usbip: vhci extension: modifications to vhci driver") introduced multiple controllers, and nports as a sys file, and claimed to read the nports from it, but it didn't. In addition, the get_nports() has been so wrong that even with 8 port lines for instance, it gets 7 (I am guessing it is due to a '\n' mess). Nevertheless, we fix it by reading the nports attribute. 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>
Diffstat (limited to 'tools/usb/usbip/libsrc')
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.c28
1 files changed, 5 insertions, 23 deletions
diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c
index ad9204773533..f659c146cdc8 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -123,33 +123,15 @@ static int refresh_imported_device_list(void)
123 123
124static int get_nports(void) 124static int get_nports(void)
125{ 125{
126 char *c; 126 const char *attr_nports;
127 int nports = 0;
128 const char *attr_status;
129 127
130 attr_status = udev_device_get_sysattr_value(vhci_driver->hc_device, 128 attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports");
131 "status"); 129 if (!attr_nports) {
132 if (!attr_status) { 130 err("udev_device_get_sysattr_value nports failed");
133 err("udev_device_get_sysattr_value failed");
134 return -1; 131 return -1;
135 } 132 }
136 133
137 /* skip a header line */ 134 return (int)strtoul(attr_nports, NULL, 10);
138 c = strchr(attr_status, '\n');
139 if (!c)
140 return 0;
141 c++;
142
143 while (*c != '\0') {
144 /* go to the next line */
145 c = strchr(c, '\n');
146 if (!c)
147 return nports;
148 c++;
149 nports += 1;
150 }
151
152 return nports;
153} 135}
154 136
155/* 137/*