1 From foo@baz Sat Jul 28 10:25:26 CEST 2018
2 From: Michael Grzeschik <m.grzeschik@pengutronix.de>
3 Date: Fri, 25 May 2018 16:23:46 +0200
4 Subject: usbip: dynamically allocate idev by nports found in sysfs
6 From: Michael Grzeschik <m.grzeschik@pengutronix.de>
8 [ Upstream commit de19ca6fd72c7dd45ad82403e7b3fe9c74ef6767 ]
10 As the amount of available ports varies by the kernels build
11 configuration. To remove the limitation of the fixed 128 ports
12 we allocate the amount of idevs by using the number we get
15 Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de>
16 Acked-by: Shuah Khan (Samsung OSG) <shuah@kernel.org>
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 tools/usb/usbip/libsrc/vhci_driver.c | 32 +++++++++++++++++++-------------
22 tools/usb/usbip/libsrc/vhci_driver.h | 3 +--
23 2 files changed, 20 insertions(+), 15 deletions(-)
25 --- a/tools/usb/usbip/libsrc/vhci_driver.c
26 +++ b/tools/usb/usbip/libsrc/vhci_driver.c
27 @@ -135,11 +135,11 @@ static int refresh_imported_device_list(
31 -static int get_nports(void)
32 +static int get_nports(struct udev_device *hc_device)
34 const char *attr_nports;
36 - attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports");
37 + attr_nports = udev_device_get_sysattr_value(hc_device, "nports");
39 err("udev_device_get_sysattr_value nports failed");
41 @@ -242,35 +242,41 @@ static int read_record(int rhport, char
43 int usbip_vhci_driver_open(void)
46 + struct udev_device *hc_device;
48 udev_context = udev_new();
50 err("udev_new failed");
54 - vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
56 /* will be freed in usbip_driver_close() */
57 - vhci_driver->hc_device =
59 udev_device_new_from_subsystem_sysname(udev_context,
61 USBIP_VHCI_DEVICE_NAME);
62 - if (!vhci_driver->hc_device) {
64 err("udev_device_new_from_subsystem_sysname failed");
68 - vhci_driver->nports = get_nports();
69 - dbg("available ports: %d", vhci_driver->nports);
71 - if (vhci_driver->nports <= 0) {
72 + nports = get_nports(hc_device);
74 err("no available ports");
76 - } else if (vhci_driver->nports > MAXNPORT) {
77 - err("port number exceeds %d", MAXNPORT);
79 + dbg("available ports: %d", nports);
81 + vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) +
82 + nports * sizeof(struct usbip_imported_device));
84 + err("vhci_driver allocation failed");
88 + vhci_driver->nports = nports;
89 + vhci_driver->hc_device = hc_device;
90 vhci_driver->ncontrollers = get_ncontrollers();
91 dbg("available controllers: %d", vhci_driver->ncontrollers);
93 @@ -285,7 +291,7 @@ int usbip_vhci_driver_open(void)
97 - udev_device_unref(vhci_driver->hc_device);
98 + udev_device_unref(hc_device);
102 --- a/tools/usb/usbip/libsrc/vhci_driver.h
103 +++ b/tools/usb/usbip/libsrc/vhci_driver.h
106 #define USBIP_VHCI_BUS_TYPE "platform"
107 #define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
108 -#define MAXNPORT 128
112 @@ -41,7 +40,7 @@ struct usbip_vhci_driver {
116 - struct usbip_imported_device idev[MAXNPORT];
117 + struct usbip_imported_device idev[];