aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Grzeschik <m.grzeschik@pengutronix.de>2018-05-25 10:23:46 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-05-31 06:43:14 -0400
commitde19ca6fd72c7dd45ad82403e7b3fe9c74ef6767 (patch)
tree254c3463c6bf29e78a43b6eae5f516c0d0c701fc
parentdbafc28955fa6779dc23d1607a0fee5e509a278b (diff)
usbip: dynamically allocate idev by nports found in sysfs
As the amount of available ports varies by the kernels build configuration. To remove the limitation of the fixed 128 ports we allocate the amount of idevs by using the number we get from the kernel. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> Acked-by: Shuah Khan (Samsung OSG) <shuah@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.c32
-rw-r--r--tools/usb/usbip/libsrc/vhci_driver.h3
2 files changed, 20 insertions, 15 deletions
diff --git a/tools/usb/usbip/libsrc/vhci_driver.c b/tools/usb/usbip/libsrc/vhci_driver.c
index c9c81614a66a..4204359c9fee 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -135,11 +135,11 @@ static int refresh_imported_device_list(void)
135 return 0; 135 return 0;
136} 136}
137 137
138static int get_nports(void) 138static int get_nports(struct udev_device *hc_device)
139{ 139{
140 const char *attr_nports; 140 const char *attr_nports;
141 141
142 attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports"); 142 attr_nports = udev_device_get_sysattr_value(hc_device, "nports");
143 if (!attr_nports) { 143 if (!attr_nports) {
144 err("udev_device_get_sysattr_value nports failed"); 144 err("udev_device_get_sysattr_value nports failed");
145 return -1; 145 return -1;
@@ -242,35 +242,41 @@ static int read_record(int rhport, char *host, unsigned long host_len,
242 242
243int usbip_vhci_driver_open(void) 243int usbip_vhci_driver_open(void)
244{ 244{
245 int nports;
246 struct udev_device *hc_device;
247
245 udev_context = udev_new(); 248 udev_context = udev_new();
246 if (!udev_context) { 249 if (!udev_context) {
247 err("udev_new failed"); 250 err("udev_new failed");
248 return -1; 251 return -1;
249 } 252 }
250 253
251 vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
252
253 /* will be freed in usbip_driver_close() */ 254 /* will be freed in usbip_driver_close() */
254 vhci_driver->hc_device = 255 hc_device =
255 udev_device_new_from_subsystem_sysname(udev_context, 256 udev_device_new_from_subsystem_sysname(udev_context,
256 USBIP_VHCI_BUS_TYPE, 257 USBIP_VHCI_BUS_TYPE,
257 USBIP_VHCI_DEVICE_NAME); 258 USBIP_VHCI_DEVICE_NAME);
258 if (!vhci_driver->hc_device) { 259 if (!hc_device) {
259 err("udev_device_new_from_subsystem_sysname failed"); 260 err("udev_device_new_from_subsystem_sysname failed");
260 goto err; 261 goto err;
261 } 262 }
262 263
263 vhci_driver->nports = get_nports(); 264 nports = get_nports(hc_device);
264 dbg("available ports: %d", vhci_driver->nports); 265 if (nports <= 0) {
265
266 if (vhci_driver->nports <= 0) {
267 err("no available ports"); 266 err("no available ports");
268 goto err; 267 goto err;
269 } else if (vhci_driver->nports > MAXNPORT) { 268 }
270 err("port number exceeds %d", MAXNPORT); 269 dbg("available ports: %d", nports);
270
271 vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) +
272 nports * sizeof(struct usbip_imported_device));
273 if (!vhci_driver) {
274 err("vhci_driver allocation failed");
271 goto err; 275 goto err;
272 } 276 }
273 277
278 vhci_driver->nports = nports;
279 vhci_driver->hc_device = hc_device;
274 vhci_driver->ncontrollers = get_ncontrollers(); 280 vhci_driver->ncontrollers = get_ncontrollers();
275 dbg("available controllers: %d", vhci_driver->ncontrollers); 281 dbg("available controllers: %d", vhci_driver->ncontrollers);
276 282
@@ -285,7 +291,7 @@ int usbip_vhci_driver_open(void)
285 return 0; 291 return 0;
286 292
287err: 293err:
288 udev_device_unref(vhci_driver->hc_device); 294 udev_device_unref(hc_device);
289 295
290 if (vhci_driver) 296 if (vhci_driver)
291 free(vhci_driver); 297 free(vhci_driver);
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h b/tools/usb/usbip/libsrc/vhci_driver.h
index 418b404d5121..6c9aca216705 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -13,7 +13,6 @@
13 13
14#define USBIP_VHCI_BUS_TYPE "platform" 14#define USBIP_VHCI_BUS_TYPE "platform"
15#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0" 15#define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
16#define MAXNPORT 128
17 16
18enum hub_speed { 17enum hub_speed {
19 HUB_SPEED_HIGH = 0, 18 HUB_SPEED_HIGH = 0,
@@ -41,7 +40,7 @@ struct usbip_vhci_driver {
41 40
42 int ncontrollers; 41 int ncontrollers;
43 int nports; 42 int nports;
44 struct usbip_imported_device idev[MAXNPORT]; 43 struct usbip_imported_device idev[];
45}; 44};
46 45
47 46