]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.60/usbip-dynamically-allocate-idev-by-nports-found-in-sysfs.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.14.60 / usbip-dynamically-allocate-idev-by-nports-found-in-sysfs.patch
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
5
6 From: Michael Grzeschik <m.grzeschik@pengutronix.de>
7
8 [ Upstream commit de19ca6fd72c7dd45ad82403e7b3fe9c74ef6767 ]
9
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
13 from the kernel.
14
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>
20 ---
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(-)
24
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(
28 return 0;
29 }
30
31 -static int get_nports(void)
32 +static int get_nports(struct udev_device *hc_device)
33 {
34 const char *attr_nports;
35
36 - attr_nports = udev_device_get_sysattr_value(vhci_driver->hc_device, "nports");
37 + attr_nports = udev_device_get_sysattr_value(hc_device, "nports");
38 if (!attr_nports) {
39 err("udev_device_get_sysattr_value nports failed");
40 return -1;
41 @@ -242,35 +242,41 @@ static int read_record(int rhport, char
42
43 int usbip_vhci_driver_open(void)
44 {
45 + int nports;
46 + struct udev_device *hc_device;
47 +
48 udev_context = udev_new();
49 if (!udev_context) {
50 err("udev_new failed");
51 return -1;
52 }
53
54 - vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
55 -
56 /* will be freed in usbip_driver_close() */
57 - vhci_driver->hc_device =
58 + hc_device =
59 udev_device_new_from_subsystem_sysname(udev_context,
60 USBIP_VHCI_BUS_TYPE,
61 USBIP_VHCI_DEVICE_NAME);
62 - if (!vhci_driver->hc_device) {
63 + if (!hc_device) {
64 err("udev_device_new_from_subsystem_sysname failed");
65 goto err;
66 }
67
68 - vhci_driver->nports = get_nports();
69 - dbg("available ports: %d", vhci_driver->nports);
70 -
71 - if (vhci_driver->nports <= 0) {
72 + nports = get_nports(hc_device);
73 + if (nports <= 0) {
74 err("no available ports");
75 goto err;
76 - } else if (vhci_driver->nports > MAXNPORT) {
77 - err("port number exceeds %d", MAXNPORT);
78 + }
79 + dbg("available ports: %d", nports);
80 +
81 + vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver) +
82 + nports * sizeof(struct usbip_imported_device));
83 + if (!vhci_driver) {
84 + err("vhci_driver allocation failed");
85 goto err;
86 }
87
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);
92
93 @@ -285,7 +291,7 @@ int usbip_vhci_driver_open(void)
94 return 0;
95
96 err:
97 - udev_device_unref(vhci_driver->hc_device);
98 + udev_device_unref(hc_device);
99
100 if (vhci_driver)
101 free(vhci_driver);
102 --- a/tools/usb/usbip/libsrc/vhci_driver.h
103 +++ b/tools/usb/usbip/libsrc/vhci_driver.h
104 @@ -13,7 +13,6 @@
105
106 #define USBIP_VHCI_BUS_TYPE "platform"
107 #define USBIP_VHCI_DEVICE_NAME "vhci_hcd.0"
108 -#define MAXNPORT 128
109
110 enum hub_speed {
111 HUB_SPEED_HIGH = 0,
112 @@ -41,7 +40,7 @@ struct usbip_vhci_driver {
113
114 int ncontrollers;
115 int nports;
116 - struct usbip_imported_device idev[MAXNPORT];
117 + struct usbip_imported_device idev[];
118 };
119
120