Diff markup
1 #include <linux/usb.h> 1 #include <linux/usb.h>
2 #include <linux/usb/ch9.h> 2 #include <linux/usb/ch9.h>
3 #include <linux/module.h> 3 #include <linux/module.h>
4 #include <linux/init.h> 4 #include <linux/init.h>
5 #include <linux/slab.h> 5 #include <linux/slab.h>
6 #include <linux/device.h> 6 #include <linux/device.h>
7 #include <asm/byteorder.h> 7 #include <asm/byteorder.h>
8 #include "usb.h" 8 #include "usb.h"
9 #include "hcd.h" 9 #include "hcd.h"
10 10
11 #define USB_MAXALTSETTING 128 11 #define USB_MAXALTSETTING 128 /* Hard limit */
12 #define USB_MAXENDPOINTS 30 12 #define USB_MAXENDPOINTS 30 /* Hard limit */
13 13
14 #define USB_MAXCONFIG 8 14 #define USB_MAXCONFIG 8 /* Arbitrary limit */
15 15
16 16
17 static inline const char *plural(int n) 17 static inline const char *plural(int n)
18 { 18 {
19 return (n == 1 ? "" : "s"); 19 return (n == 1 ? "" : "s");
20 } 20 }
21 21
>> 22 /* FIXME: this is a kludge */
>> 23 static int find_next_descriptor_more(unsigned char *buffer, int size,
>> 24 int dt1, int dt2, int dt3, int *num_skipped)
>> 25 {
>> 26 struct usb_descriptor_header *h;
>> 27 int n = 0;
>> 28 unsigned char *buffer0 = buffer;
>> 29
>> 30 /* Find the next descriptor of type dt1 or dt2 or dt3 */
>> 31 while (size > 0) {
>> 32 h = (struct usb_descriptor_header *) buffer;
>> 33 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2 ||
>> 34 h->bDescriptorType == dt3)
>> 35 break;
>> 36 buffer += h->bLength;
>> 37 size -= h->bLength;
>> 38 ++n;
>> 39 }
>> 40
>> 41 /* Store the number of descriptors skipped and return the
>> 42 * number of bytes skipped */
>> 43 if (num_skipped)
>> 44 *num_skipped = n;
>> 45 return buffer - buffer0;
>> 46 }
>> 47
22 static int find_next_descriptor(unsigned char 48 static int find_next_descriptor(unsigned char *buffer, int size,
23 int dt1, int dt2, int *num_skipped) 49 int dt1, int dt2, int *num_skipped)
24 { 50 {
25 struct usb_descriptor_header *h; 51 struct usb_descriptor_header *h;
26 int n = 0; 52 int n = 0;
27 unsigned char *buffer0 = buffer; 53 unsigned char *buffer0 = buffer;
28 54
29 /* Find the next descriptor of type dt 55 /* Find the next descriptor of type dt1 or dt2 */
30 while (size > 0) { 56 while (size > 0) {
31 h = (struct usb_descriptor_hea 57 h = (struct usb_descriptor_header *) buffer;
32 if (h->bDescriptorType == dt1 58 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2)
33 break; 59 break;
34 buffer += h->bLength; 60 buffer += h->bLength;
35 size -= h->bLength; 61 size -= h->bLength;
36 ++n; 62 ++n;
37 } 63 }
38 64
39 /* Store the number of descriptors ski 65 /* Store the number of descriptors skipped and return the
40 * number of bytes skipped */ 66 * number of bytes skipped */
41 if (num_skipped) 67 if (num_skipped)
42 *num_skipped = n; 68 *num_skipped = n;
43 return buffer - buffer0; 69 return buffer - buffer0;
44 } 70 }
45 71
>> 72 static int usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
>> 73 int inum, int asnum, struct usb_host_endpoint *ep,
>> 74 int num_ep, unsigned char *buffer, int size)
>> 75 {
>> 76 unsigned char *buffer_start = buffer;
>> 77 struct usb_ss_ep_comp_descriptor *desc;
>> 78 int retval;
>> 79 int num_skipped;
>> 80 int max_tx;
>> 81 int i;
>> 82
>> 83 desc = (struct usb_ss_ep_comp_descriptor *) buffer;
>> 84 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP) {
>> 85 dev_warn(ddev, "No SuperSpeed endpoint companion for config %d "
>> 86 " interface %d altsetting %d ep %d: "
>> 87 "using minimum values\n",
>> 88 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 89 /*
>> 90 * The next descriptor is for an Endpoint or Interface,
>> 91 * no extra descriptors to copy into the companion structure,
>> 92 * and we didn't eat up any of the buffer.
>> 93 */
>> 94 return 0;
>> 95 }
>> 96 memcpy(&ep->ss_ep_comp->desc, desc, USB_DT_SS_EP_COMP_SIZE);
>> 97 desc = &ep->ss_ep_comp->desc;
>> 98 buffer += desc->bLength;
>> 99 size -= desc->bLength;
>> 100
>> 101 /* Eat up the other descriptors we don't care about */
>> 102 ep->ss_ep_comp->extra = buffer;
>> 103 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
>> 104 USB_DT_INTERFACE, &num_skipped);
>> 105 ep->ss_ep_comp->extralen = i;
>> 106 buffer += i;
>> 107 size -= i;
>> 108 retval = buffer - buffer_start;
>> 109 if (num_skipped > 0)
>> 110 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
>> 111 num_skipped, plural(num_skipped),
>> 112 "SuperSpeed endpoint companion");
>> 113
>> 114 /* Check the various values */
>> 115 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) {
>> 116 dev_warn(ddev, "Control endpoint with bMaxBurst = %d in "
>> 117 "config %d interface %d altsetting %d ep %d: "
>> 118 "setting to zero\n", desc->bMaxBurst,
>> 119 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 120 desc->bMaxBurst = 0;
>> 121 }
>> 122 if (desc->bMaxBurst > 15) {
>> 123 dev_warn(ddev, "Endpoint with bMaxBurst = %d in "
>> 124 "config %d interface %d altsetting %d ep %d: "
>> 125 "setting to 15\n", desc->bMaxBurst,
>> 126 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 127 desc->bMaxBurst = 15;
>> 128 }
>> 129 if ((usb_endpoint_xfer_control(&ep->desc) || usb_endpoint_xfer_int(&ep->desc))
>> 130 && desc->bmAttributes != 0) {
>> 131 dev_warn(ddev, "%s endpoint with bmAttributes = %d in "
>> 132 "config %d interface %d altsetting %d ep %d: "
>> 133 "setting to zero\n",
>> 134 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk",
>> 135 desc->bmAttributes,
>> 136 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 137 desc->bmAttributes = 0;
>> 138 }
>> 139 if (usb_endpoint_xfer_bulk(&ep->desc) && desc->bmAttributes > 16) {
>> 140 dev_warn(ddev, "Bulk endpoint with more than 65536 streams in "
>> 141 "config %d interface %d altsetting %d ep %d: "
>> 142 "setting to max\n",
>> 143 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 144 desc->bmAttributes = 16;
>> 145 }
>> 146 if (usb_endpoint_xfer_isoc(&ep->desc) && desc->bmAttributes > 2) {
>> 147 dev_warn(ddev, "Isoc endpoint has Mult of %d in "
>> 148 "config %d interface %d altsetting %d ep %d: "
>> 149 "setting to 3\n", desc->bmAttributes + 1,
>> 150 cfgno, inum, asnum, ep->desc.bEndpointAddress);
>> 151 desc->bmAttributes = 2;
>> 152 }
>> 153 if (usb_endpoint_xfer_isoc(&ep->desc)) {
>> 154 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1) *
>> 155 (desc->bmAttributes + 1);
>> 156 } else if (usb_endpoint_xfer_int(&ep->desc)) {
>> 157 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1);
>> 158 } else {
>> 159 goto valid;
>> 160 }
>> 161 if (desc->wBytesPerInterval > max_tx) {
>> 162 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in "
>> 163 "config %d interface %d altsetting %d ep %d: "
>> 164 "setting to %d\n",
>> 165 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int",
>> 166 desc->wBytesPerInterval,
>> 167 cfgno, inum, asnum, ep->desc.bEndpointAddress,
>> 168 max_tx);
>> 169 desc->wBytesPerInterval = max_tx;
>> 170 }
>> 171 valid:
>> 172 return retval;
>> 173 }
>> 174
46 static int usb_parse_endpoint(struct device *d 175 static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
47 int asnum, struct usb_host_interface *ifp, 176 int asnum, struct usb_host_interface *ifp, int num_ep,
48 unsigned char *buffer, int size) 177 unsigned char *buffer, int size)
49 { 178 {
50 unsigned char *buffer0 = buffer; 179 unsigned char *buffer0 = buffer;
51 struct usb_endpoint_descriptor *d; 180 struct usb_endpoint_descriptor *d;
52 struct usb_host_endpoint *endpoint; 181 struct usb_host_endpoint *endpoint;
53 int n, i, j; !! 182 int n, i, j, retval;
54 183
55 d = (struct usb_endpoint_descriptor *) 184 d = (struct usb_endpoint_descriptor *) buffer;
56 buffer += d->bLength; 185 buffer += d->bLength;
57 size -= d->bLength; 186 size -= d->bLength;
58 187
59 if (d->bLength >= USB_DT_ENDPOINT_AUDI 188 if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE)
60 n = USB_DT_ENDPOINT_AUDIO_SIZE 189 n = USB_DT_ENDPOINT_AUDIO_SIZE;
61 else if (d->bLength >= USB_DT_ENDPOINT 190 else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
62 n = USB_DT_ENDPOINT_SIZE; 191 n = USB_DT_ENDPOINT_SIZE;
63 else { 192 else {
64 dev_warn(ddev, "config %d inte 193 dev_warn(ddev, "config %d interface %d altsetting %d has an "
65 "invalid endpoint descript 194 "invalid endpoint descriptor of length %d, skipping\n",
66 cfgno, inum, asnum, d->bLe 195 cfgno, inum, asnum, d->bLength);
67 goto skip_to_next_endpoint_or_ 196 goto skip_to_next_endpoint_or_interface_descriptor;
68 } 197 }
69 198
70 i = d->bEndpointAddress & ~USB_ENDPOIN 199 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;
71 if (i >= 16 || i == 0) { 200 if (i >= 16 || i == 0) {
72 dev_warn(ddev, "config %d inte 201 dev_warn(ddev, "config %d interface %d altsetting %d has an "
73 "invalid endpoint with add 202 "invalid endpoint with address 0x%X, skipping\n",
74 cfgno, inum, asnum, d->bEn 203 cfgno, inum, asnum, d->bEndpointAddress);
75 goto skip_to_next_endpoint_or_ 204 goto skip_to_next_endpoint_or_interface_descriptor;
76 } 205 }
77 206
78 /* Only store as many endpoints as we 207 /* Only store as many endpoints as we have room for */
79 if (ifp->desc.bNumEndpoints >= num_ep) 208 if (ifp->desc.bNumEndpoints >= num_ep)
80 goto skip_to_next_endpoint_or_ 209 goto skip_to_next_endpoint_or_interface_descriptor;
81 210
82 endpoint = &ifp->endpoint[ifp->desc.bN 211 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints];
83 ++ifp->desc.bNumEndpoints; 212 ++ifp->desc.bNumEndpoints;
84 213
85 memcpy(&endpoint->desc, d, n); 214 memcpy(&endpoint->desc, d, n);
86 INIT_LIST_HEAD(&endpoint->urb_list); 215 INIT_LIST_HEAD(&endpoint->urb_list);
87 216
88 /* Fix up bInterval values outside the 217 /* Fix up bInterval values outside the legal range. Use 32 ms if no
89 * proper value can be guessed. */ 218 * proper value can be guessed. */
90 i = 0; /* i = min, j = max, n 219 i = 0; /* i = min, j = max, n = default */
91 j = 255; 220 j = 255;
92 if (usb_endpoint_xfer_int(d)) { 221 if (usb_endpoint_xfer_int(d)) {
93 i = 1; 222 i = 1;
94 switch (to_usb_device(ddev)->s 223 switch (to_usb_device(ddev)->speed) {
>> 224 case USB_SPEED_SUPER:
95 case USB_SPEED_HIGH: 225 case USB_SPEED_HIGH:
96 /* Many device manufac 226 /* Many device manufacturers are using full-speed
97 * bInterval values in 227 * bInterval values in high-speed interrupt endpoint
98 * descriptors. Try to 228 * descriptors. Try to fix those and fall back to a
99 * 32 ms default value 229 * 32 ms default value otherwise. */
100 n = fls(d->bInterval*8 230 n = fls(d->bInterval*8);
101 if (n == 0) 231 if (n == 0)
102 n = 9; /* 32 232 n = 9; /* 32 ms = 2^(9-1) uframes */
103 j = 16; 233 j = 16;
104 break; 234 break;
105 default: /* USB 235 default: /* USB_SPEED_FULL or _LOW */
106 /* For low-speed, 10 m 236 /* For low-speed, 10 ms is the official minimum.
107 * But some "overclock 237 * But some "overclocked" devices might want faster
108 * polling so we'll al 238 * polling so we'll allow it. */
109 n = 32; 239 n = 32;
110 break; 240 break;
111 } 241 }
112 } else if (usb_endpoint_xfer_isoc(d)) 242 } else if (usb_endpoint_xfer_isoc(d)) {
113 i = 1; 243 i = 1;
114 j = 16; 244 j = 16;
115 switch (to_usb_device(ddev)->s 245 switch (to_usb_device(ddev)->speed) {
116 case USB_SPEED_HIGH: 246 case USB_SPEED_HIGH:
117 n = 9; /* 32 247 n = 9; /* 32 ms = 2^(9-1) uframes */
118 break; 248 break;
119 default: /* USB 249 default: /* USB_SPEED_FULL */
120 n = 6; /* 32 250 n = 6; /* 32 ms = 2^(6-1) frames */
121 break; 251 break;
122 } 252 }
123 } 253 }
124 if (d->bInterval < i || d->bInterval > 254 if (d->bInterval < i || d->bInterval > j) {
125 dev_warn(ddev, "config %d inte 255 dev_warn(ddev, "config %d interface %d altsetting %d "
126 "endpoint 0x%X has an inva 256 "endpoint 0x%X has an invalid bInterval %d, "
127 "changing to %d\n", 257 "changing to %d\n",
128 cfgno, inum, asnum, 258 cfgno, inum, asnum,
129 d->bEndpointAddress, d->bI 259 d->bEndpointAddress, d->bInterval, n);
130 endpoint->desc.bInterval = n; 260 endpoint->desc.bInterval = n;
131 } 261 }
132 262
133 /* Some buggy low-speed devices have B 263 /* Some buggy low-speed devices have Bulk endpoints, which is
134 * explicitly forbidden by the USB spe 264 * explicitly forbidden by the USB spec. In an attempt to make
135 * them usable, we will try treating t 265 * them usable, we will try treating them as Interrupt endpoints.
136 */ 266 */
137 if (to_usb_device(ddev)->speed == USB_ 267 if (to_usb_device(ddev)->speed == USB_SPEED_LOW &&
138 usb_endpoint_xfer_bulk 268 usb_endpoint_xfer_bulk(d)) {
139 dev_warn(ddev, "config %d inte 269 dev_warn(ddev, "config %d interface %d altsetting %d "
140 "endpoint 0x%X is Bulk; ch 270 "endpoint 0x%X is Bulk; changing to Interrupt\n",
141 cfgno, inum, asnum, d->bEn 271 cfgno, inum, asnum, d->bEndpointAddress);
142 endpoint->desc.bmAttributes = 272 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
143 endpoint->desc.bInterval = 1; 273 endpoint->desc.bInterval = 1;
144 if (le16_to_cpu(endpoint->desc 274 if (le16_to_cpu(endpoint->desc.wMaxPacketSize) > 8)
145 endpoint->desc.wMaxPac 275 endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
146 } 276 }
147 277
148 /* Skip over any Class Specific or Ven !! 278 /*
149 * find the next endpoint or interface !! 279 * Some buggy high speed devices have bulk endpoints using
150 endpoint->extra = buffer; !! 280 * maxpacket sizes other than 512. High speed HCDs may not
151 i = find_next_descriptor(buffer, size, !! 281 * be able to handle that particular bug, so let's warn...
152 USB_DT_INTERFACE, &n); !! 282 */
153 endpoint->extralen = i; !! 283 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
>> 284 && usb_endpoint_xfer_bulk(d)) {
>> 285 unsigned maxp;
>> 286
>> 287 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff;
>> 288 if (maxp != 512)
>> 289 dev_warn(ddev, "config %d interface %d altsetting %d "
>> 290 "bulk endpoint 0x%X has invalid maxpacket %d\n",
>> 291 cfgno, inum, asnum, d->bEndpointAddress,
>> 292 maxp);
>> 293 }
>> 294 /* Allocate room for and parse any SS endpoint companion descriptors */
>> 295 if (to_usb_device(ddev)->speed == USB_SPEED_SUPER) {
>> 296 endpoint->extra = buffer;
>> 297 i = find_next_descriptor_more(buffer, size, USB_DT_SS_ENDPOINT_COMP,
>> 298 USB_DT_ENDPOINT, USB_DT_INTERFACE, &n);
>> 299 endpoint->extralen = i;
>> 300 buffer += i;
>> 301 size -= i;
>> 302
>> 303 /* Allocate space for the SS endpoint companion descriptor */
>> 304 endpoint->ss_ep_comp = kzalloc(sizeof(struct usb_host_ss_ep_comp),
>> 305 GFP_KERNEL);
>> 306 if (!endpoint->ss_ep_comp)
>> 307 return -ENOMEM;
>> 308
>> 309 /* Fill in some default values (may be overwritten later) */
>> 310 endpoint->ss_ep_comp->desc.bLength = USB_DT_SS_EP_COMP_SIZE;
>> 311 endpoint->ss_ep_comp->desc.bDescriptorType = USB_DT_SS_ENDPOINT_COMP;
>> 312 endpoint->ss_ep_comp->desc.bMaxBurst = 0;
>> 313 /*
>> 314 * Leave bmAttributes as zero, which will mean no streams for
>> 315 * bulk, and isoc won't support multiple bursts of packets.
>> 316 * With bursts of only one packet, and a Mult of 1, the max
>> 317 * amount of data moved per endpoint service interval is one
>> 318 * packet.
>> 319 */
>> 320 if (usb_endpoint_xfer_isoc(&endpoint->desc) ||
>> 321 usb_endpoint_xfer_int(&endpoint->desc))
>> 322 endpoint->ss_ep_comp->desc.wBytesPerInterval =
>> 323 endpoint->desc.wMaxPacketSize;
>> 324
>> 325 if (size > 0) {
>> 326 retval = usb_parse_ss_endpoint_companion(ddev, cfgno,
>> 327 inum, asnum, endpoint, num_ep, buffer,
>> 328 size);
>> 329 if (retval >= 0) {
>> 330 buffer += retval;
>> 331 retval = buffer - buffer0;
>> 332 }
>> 333 } else {
>> 334 dev_warn(ddev, "config %d interface %d altsetting %d "
>> 335 "endpoint 0x%X has no "
>> 336 "SuperSpeed companion descriptor\n",
>> 337 cfgno, inum, asnum, d->bEndpointAddress);
>> 338 retval = buffer - buffer0;
>> 339 }
>> 340 } else {
>> 341 /* Skip over any Class Specific or Vendor Specific descriptors;
>> 342 * find the next endpoint or interface descriptor */
>> 343 endpoint->extra = buffer;
>> 344 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
>> 345 USB_DT_INTERFACE, &n);
>> 346 endpoint->extralen = i;
>> 347 retval = buffer - buffer0 + i;
>> 348 }
154 if (n > 0) 349 if (n > 0)
155 dev_dbg(ddev, "skipped %d desc 350 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
156 n, plural(n), "endpoint"); 351 n, plural(n), "endpoint");
157 return buffer - buffer0 + i; !! 352 return retval;
158 353
159 skip_to_next_endpoint_or_interface_descriptor: 354 skip_to_next_endpoint_or_interface_descriptor:
160 i = find_next_descriptor(buffer, size, 355 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
161 USB_DT_INTERFACE, NULL); 356 USB_DT_INTERFACE, NULL);
162 return buffer - buffer0 + i; 357 return buffer - buffer0 + i;
163 } 358 }
164 359
165 void usb_release_interface_cache(struct kref * 360 void usb_release_interface_cache(struct kref *ref)
166 { 361 {
167 struct usb_interface_cache *intfc = re 362 struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref);
168 int j; 363 int j;
169 364
170 for (j = 0; j < intfc->num_altsetting; 365 for (j = 0; j < intfc->num_altsetting; j++) {
171 struct usb_host_interface *alt 366 struct usb_host_interface *alt = &intfc->altsetting[j];
172 367
173 kfree(alt->endpoint); 368 kfree(alt->endpoint);
174 kfree(alt->string); 369 kfree(alt->string);
175 } 370 }
176 kfree(intfc); 371 kfree(intfc);
177 } 372 }
178 373
179 static int usb_parse_interface(struct device * 374 static int usb_parse_interface(struct device *ddev, int cfgno,
180 struct usb_host_config *config, unsigned c 375 struct usb_host_config *config, unsigned char *buffer, int size,
181 u8 inums[], u8 nalts[]) 376 u8 inums[], u8 nalts[])
182 { 377 {
183 unsigned char *buffer0 = buffer; 378 unsigned char *buffer0 = buffer;
184 struct usb_interface_descriptor *d; 379 struct usb_interface_descriptor *d;
185 int inum, asnum; 380 int inum, asnum;
186 struct usb_interface_cache *intfc; 381 struct usb_interface_cache *intfc;
187 struct usb_host_interface *alt; 382 struct usb_host_interface *alt;
188 int i, n; 383 int i, n;
189 int len, retval; 384 int len, retval;
190 int num_ep, num_ep_orig; 385 int num_ep, num_ep_orig;
191 386
192 d = (struct usb_interface_descriptor * 387 d = (struct usb_interface_descriptor *) buffer;
193 buffer += d->bLength; 388 buffer += d->bLength;
194 size -= d->bLength; 389 size -= d->bLength;
195 390
196 if (d->bLength < USB_DT_INTERFACE_SIZE 391 if (d->bLength < USB_DT_INTERFACE_SIZE)
197 goto skip_to_next_interface_de 392 goto skip_to_next_interface_descriptor;
198 393
199 /* Which interface entry is this? */ 394 /* Which interface entry is this? */
200 intfc = NULL; 395 intfc = NULL;
201 inum = d->bInterfaceNumber; 396 inum = d->bInterfaceNumber;
202 for (i = 0; i < config->desc.bNumInter 397 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
203 if (inums[i] == inum) { 398 if (inums[i] == inum) {
204 intfc = config->intf_c 399 intfc = config->intf_cache[i];
205 break; 400 break;
206 } 401 }
207 } 402 }
208 if (!intfc || intfc->num_altsetting >= 403 if (!intfc || intfc->num_altsetting >= nalts[i])
209 goto skip_to_next_interface_de 404 goto skip_to_next_interface_descriptor;
210 405
211 /* Check for duplicate altsetting entr 406 /* Check for duplicate altsetting entries */
212 asnum = d->bAlternateSetting; 407 asnum = d->bAlternateSetting;
213 for ((i = 0, alt = &intfc->altsetting[ 408 for ((i = 0, alt = &intfc->altsetting[0]);
214 i < intfc->num_altsetting; 409 i < intfc->num_altsetting;
215 (++i, ++alt)) { 410 (++i, ++alt)) {
216 if (alt->desc.bAlternateSettin 411 if (alt->desc.bAlternateSetting == asnum) {
217 dev_warn(ddev, "Duplic 412 dev_warn(ddev, "Duplicate descriptor for config %d "
218 "interface %d alts 413 "interface %d altsetting %d, skipping\n",
219 cfgno, inum, asnum 414 cfgno, inum, asnum);
220 goto skip_to_next_inte 415 goto skip_to_next_interface_descriptor;
221 } 416 }
222 } 417 }
223 418
224 ++intfc->num_altsetting; 419 ++intfc->num_altsetting;
225 memcpy(&alt->desc, d, USB_DT_INTERFACE 420 memcpy(&alt->desc, d, USB_DT_INTERFACE_SIZE);
226 421
227 /* Skip over any Class Specific or Ven 422 /* Skip over any Class Specific or Vendor Specific descriptors;
228 * find the first endpoint or interfac 423 * find the first endpoint or interface descriptor */
229 alt->extra = buffer; 424 alt->extra = buffer;
230 i = find_next_descriptor(buffer, size, 425 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
231 USB_DT_INTERFACE, &n); 426 USB_DT_INTERFACE, &n);
232 alt->extralen = i; 427 alt->extralen = i;
233 if (n > 0) 428 if (n > 0)
234 dev_dbg(ddev, "skipped %d desc 429 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
235 n, plural(n), "interface") 430 n, plural(n), "interface");
236 buffer += i; 431 buffer += i;
237 size -= i; 432 size -= i;
238 433
239 /* Allocate space for the right(?) num 434 /* Allocate space for the right(?) number of endpoints */
240 num_ep = num_ep_orig = alt->desc.bNumE 435 num_ep = num_ep_orig = alt->desc.bNumEndpoints;
241 alt->desc.bNumEndpoints = 0; 436 alt->desc.bNumEndpoints = 0; /* Use as a counter */
242 if (num_ep > USB_MAXENDPOINTS) { 437 if (num_ep > USB_MAXENDPOINTS) {
243 dev_warn(ddev, "too many endpo 438 dev_warn(ddev, "too many endpoints for config %d interface %d "
244 "altsetting %d: %d, using 439 "altsetting %d: %d, using maximum allowed: %d\n",
245 cfgno, inum, asnum, num_ep 440 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);
246 num_ep = USB_MAXENDPOINTS; 441 num_ep = USB_MAXENDPOINTS;
247 } 442 }
248 443
249 if (num_ep > 0) { 444 if (num_ep > 0) {
250 /* Can't allocate 0 bytes */ 445 /* Can't allocate 0 bytes */
251 len = sizeof(struct usb_host_e 446 len = sizeof(struct usb_host_endpoint) * num_ep;
252 alt->endpoint = kzalloc(len, G 447 alt->endpoint = kzalloc(len, GFP_KERNEL);
253 if (!alt->endpoint) 448 if (!alt->endpoint)
254 return -ENOMEM; 449 return -ENOMEM;
255 } 450 }
256 451
257 /* Parse all the endpoint descriptors 452 /* Parse all the endpoint descriptors */
258 n = 0; 453 n = 0;
259 while (size > 0) { 454 while (size > 0) {
260 if (((struct usb_descriptor_he 455 if (((struct usb_descriptor_header *) buffer)->bDescriptorType
261 == USB_DT_INTERFACE) 456 == USB_DT_INTERFACE)
262 break; 457 break;
263 retval = usb_parse_endpoint(dd 458 retval = usb_parse_endpoint(ddev, cfgno, inum, asnum, alt,
264 num_ep, buffer, size); 459 num_ep, buffer, size);
265 if (retval < 0) 460 if (retval < 0)
266 return retval; 461 return retval;
267 ++n; 462 ++n;
268 463
269 buffer += retval; 464 buffer += retval;
270 size -= retval; 465 size -= retval;
271 } 466 }
272 467
273 if (n != num_ep_orig) 468 if (n != num_ep_orig)
274 dev_warn(ddev, "config %d inte 469 dev_warn(ddev, "config %d interface %d altsetting %d has %d "
275 "endpoint descriptor%s, di 470 "endpoint descriptor%s, different from the interface "
276 "descriptor's value: %d\n" 471 "descriptor's value: %d\n",
277 cfgno, inum, asnum, n, plu 472 cfgno, inum, asnum, n, plural(n), num_ep_orig);
278 return buffer - buffer0; 473 return buffer - buffer0;
279 474
280 skip_to_next_interface_descriptor: 475 skip_to_next_interface_descriptor:
281 i = find_next_descriptor(buffer, size, 476 i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
282 USB_DT_INTERFACE, NULL); 477 USB_DT_INTERFACE, NULL);
283 return buffer - buffer0 + i; 478 return buffer - buffer0 + i;
284 } 479 }
285 480
286 static int usb_parse_configuration(struct devi 481 static int usb_parse_configuration(struct device *ddev, int cfgidx,
287 struct usb_host_config *config, unsigned c 482 struct usb_host_config *config, unsigned char *buffer, int size)
288 { 483 {
289 unsigned char *buffer0 = buffer; 484 unsigned char *buffer0 = buffer;
290 int cfgno; 485 int cfgno;
291 int nintf, nintf_orig; 486 int nintf, nintf_orig;
292 int i, j, n; 487 int i, j, n;
293 struct usb_interface_cache *intfc; 488 struct usb_interface_cache *intfc;
294 unsigned char *buffer2; 489 unsigned char *buffer2;
295 int size2; 490 int size2;
296 struct usb_descriptor_header *header; 491 struct usb_descriptor_header *header;
297 int len, retval; 492 int len, retval;
298 u8 inums[USB_MAXINTERFACES], nalts[USB 493 u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
299 unsigned iad_num = 0; 494 unsigned iad_num = 0;
300 495
301 memcpy(&config->desc, buffer, USB_DT_C 496 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
302 if (config->desc.bDescriptorType != US 497 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
303 config->desc.bLength < USB_DT_CONF 498 config->desc.bLength < USB_DT_CONFIG_SIZE) {
304 dev_err(ddev, "invalid descrip 499 dev_err(ddev, "invalid descriptor for config index %d: "
305 "type = 0x%X, length = %d\ 500 "type = 0x%X, length = %d\n", cfgidx,
306 config->desc.bDescriptorTy 501 config->desc.bDescriptorType, config->desc.bLength);
307 return -EINVAL; 502 return -EINVAL;
308 } 503 }
309 cfgno = config->desc.bConfigurationVal 504 cfgno = config->desc.bConfigurationValue;
310 505
311 buffer += config->desc.bLength; 506 buffer += config->desc.bLength;
312 size -= config->desc.bLength; 507 size -= config->desc.bLength;
313 508
314 nintf = nintf_orig = config->desc.bNum 509 nintf = nintf_orig = config->desc.bNumInterfaces;
315 if (nintf > USB_MAXINTERFACES) { 510 if (nintf > USB_MAXINTERFACES) {
316 dev_warn(ddev, "config %d has 511 dev_warn(ddev, "config %d has too many interfaces: %d, "
317 "using maximum allowed: %d 512 "using maximum allowed: %d\n",
318 cfgno, nintf, USB_MAXINTER 513 cfgno, nintf, USB_MAXINTERFACES);
319 nintf = USB_MAXINTERFACES; 514 nintf = USB_MAXINTERFACES;
320 } 515 }
321 516
322 /* Go through the descriptors, checkin 517 /* Go through the descriptors, checking their length and counting the
323 * number of altsettings for each inte 518 * number of altsettings for each interface */
324 n = 0; 519 n = 0;
325 for ((buffer2 = buffer, size2 = size); 520 for ((buffer2 = buffer, size2 = size);
326 size2 > 0; 521 size2 > 0;
327 (buffer2 += header->bLength, size 522 (buffer2 += header->bLength, size2 -= header->bLength)) {
328 523
329 if (size2 < sizeof(struct usb_ 524 if (size2 < sizeof(struct usb_descriptor_header)) {
330 dev_warn(ddev, "config 525 dev_warn(ddev, "config %d descriptor has %d excess "
331 "byte%s, ignoring\ 526 "byte%s, ignoring\n",
332 cfgno, size2, plur 527 cfgno, size2, plural(size2));
333 break; 528 break;
334 } 529 }
335 530
336 header = (struct usb_descripto 531 header = (struct usb_descriptor_header *) buffer2;
337 if ((header->bLength > size2) 532 if ((header->bLength > size2) || (header->bLength < 2)) {
338 dev_warn(ddev, "config 533 dev_warn(ddev, "config %d has an invalid descriptor "
339 "of length %d, ski 534 "of length %d, skipping remainder of the config\n",
340 cfgno, header->bLe 535 cfgno, header->bLength);
341 break; 536 break;
342 } 537 }
343 538
344 if (header->bDescriptorType == 539 if (header->bDescriptorType == USB_DT_INTERFACE) {
345 struct usb_interface_d 540 struct usb_interface_descriptor *d;
346 int inum; 541 int inum;
347 542
348 d = (struct usb_interf 543 d = (struct usb_interface_descriptor *) header;
349 if (d->bLength < USB_D 544 if (d->bLength < USB_DT_INTERFACE_SIZE) {
350 dev_warn(ddev, 545 dev_warn(ddev, "config %d has an invalid "
351 "interface 546 "interface descriptor of length %d, "
352 "skipping\ 547 "skipping\n", cfgno, d->bLength);
353 continue; 548 continue;
354 } 549 }
355 550
356 inum = d->bInterfaceNu 551 inum = d->bInterfaceNumber;
357 if (inum >= nintf_orig 552 if (inum >= nintf_orig)
358 dev_warn(ddev, 553 dev_warn(ddev, "config %d has an invalid "
359 "interface 554 "interface number: %d but max is %d\n",
360 cfgno, inu 555 cfgno, inum, nintf_orig - 1);
361 556
362 /* Have we already enc 557 /* Have we already encountered this interface?
363 * Count its altsettin 558 * Count its altsettings */
364 for (i = 0; i < n; ++i 559 for (i = 0; i < n; ++i) {
365 if (inums[i] = 560 if (inums[i] == inum)
366 break; 561 break;
367 } 562 }
368 if (i < n) { 563 if (i < n) {
369 if (nalts[i] < 564 if (nalts[i] < 255)
370 ++nalt 565 ++nalts[i];
371 } else if (n < USB_MAX 566 } else if (n < USB_MAXINTERFACES) {
372 inums[n] = inu 567 inums[n] = inum;
373 nalts[n] = 1; 568 nalts[n] = 1;
374 ++n; 569 ++n;
375 } 570 }
376 571
377 } else if (header->bDescriptor 572 } else if (header->bDescriptorType ==
378 USB_DT_INTERFA 573 USB_DT_INTERFACE_ASSOCIATION) {
379 if (iad_num == USB_MAX 574 if (iad_num == USB_MAXIADS) {
380 dev_warn(ddev, 575 dev_warn(ddev, "found more Interface "
381 576 "Association Descriptors "
382 577 "than allocated for in "
383 578 "configuration %d\n", cfgno);
384 } else { 579 } else {
385 config->intf_a 580 config->intf_assoc[iad_num] =
386 (struc 581 (struct usb_interface_assoc_descriptor
387 *)head 582 *)header;
388 iad_num++; 583 iad_num++;
389 } 584 }
390 585
391 } else if (header->bDescriptor 586 } else if (header->bDescriptorType == USB_DT_DEVICE ||
392 header->bDescripto 587 header->bDescriptorType == USB_DT_CONFIG)
393 dev_warn(ddev, "config 588 dev_warn(ddev, "config %d contains an unexpected "
394 "descriptor of typ 589 "descriptor of type 0x%X, skipping\n",
395 cfgno, header->bDe 590 cfgno, header->bDescriptorType);
396 591
397 } /* for ((buffer2 = buffer, siz 592 } /* for ((buffer2 = buffer, size2 = size); ...) */
398 size = buffer2 - buffer; 593 size = buffer2 - buffer;
399 config->desc.wTotalLength = cpu_to_le1 594 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);
400 595
401 if (n != nintf) 596 if (n != nintf)
402 dev_warn(ddev, "config %d has 597 dev_warn(ddev, "config %d has %d interface%s, different from "
403 "the descriptor's value: % 598 "the descriptor's value: %d\n",
404 cfgno, n, plural(n), nintf 599 cfgno, n, plural(n), nintf_orig);
405 else if (n == 0) 600 else if (n == 0)
406 dev_warn(ddev, "config %d has 601 dev_warn(ddev, "config %d has no interfaces?\n", cfgno);
407 config->desc.bNumInterfaces = nintf = 602 config->desc.bNumInterfaces = nintf = n;
408 603
409 /* Check for missing interface numbers 604 /* Check for missing interface numbers */
410 for (i = 0; i < nintf; ++i) { 605 for (i = 0; i < nintf; ++i) {
411 for (j = 0; j < nintf; ++j) { 606 for (j = 0; j < nintf; ++j) {
412 if (inums[j] == i) 607 if (inums[j] == i)
413 break; 608 break;
414 } 609 }
415 if (j >= nintf) 610 if (j >= nintf)
416 dev_warn(ddev, "config 611 dev_warn(ddev, "config %d has no interface number "
417 "%d\n", cfgno, i); 612 "%d\n", cfgno, i);
418 } 613 }
419 614
420 /* Allocate the usb_interface_caches a 615 /* Allocate the usb_interface_caches and altsetting arrays */
421 for (i = 0; i < nintf; ++i) { 616 for (i = 0; i < nintf; ++i) {
422 j = nalts[i]; 617 j = nalts[i];
423 if (j > USB_MAXALTSETTING) { 618 if (j > USB_MAXALTSETTING) {
424 dev_warn(ddev, "too ma 619 dev_warn(ddev, "too many alternate settings for "
425 "config %d interfa 620 "config %d interface %d: %d, "
426 "using maximum all 621 "using maximum allowed: %d\n",
427 cfgno, inums[i], j 622 cfgno, inums[i], j, USB_MAXALTSETTING);
428 nalts[i] = j = USB_MAX 623 nalts[i] = j = USB_MAXALTSETTING;
429 } 624 }
430 625
431 len = sizeof(*intfc) + sizeof( 626 len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
432 config->intf_cache[i] = intfc 627 config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
433 if (!intfc) 628 if (!intfc)
434 return -ENOMEM; 629 return -ENOMEM;
435 kref_init(&intfc->ref); 630 kref_init(&intfc->ref);
436 } 631 }
437 632
>> 633 /* FIXME: parse the BOS descriptor */
>> 634
438 /* Skip over any Class Specific or Ven 635 /* Skip over any Class Specific or Vendor Specific descriptors;
439 * find the first interface descriptor 636 * find the first interface descriptor */
440 config->extra = buffer; 637 config->extra = buffer;
441 i = find_next_descriptor(buffer, size, 638 i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
442 USB_DT_INTERFACE, &n); 639 USB_DT_INTERFACE, &n);
443 config->extralen = i; 640 config->extralen = i;
444 if (n > 0) 641 if (n > 0)
445 dev_dbg(ddev, "skipped %d desc 642 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
446 n, plural(n), "configurati 643 n, plural(n), "configuration");
447 buffer += i; 644 buffer += i;
448 size -= i; 645 size -= i;
449 646
450 /* Parse all the interface/altsetting 647 /* Parse all the interface/altsetting descriptors */
451 while (size > 0) { 648 while (size > 0) {
452 retval = usb_parse_interface(d 649 retval = usb_parse_interface(ddev, cfgno, config,
453 buffer, size, inums, nalts 650 buffer, size, inums, nalts);
454 if (retval < 0) 651 if (retval < 0)
455 return retval; 652 return retval;
456 653
457 buffer += retval; 654 buffer += retval;
458 size -= retval; 655 size -= retval;
459 } 656 }
460 657
461 /* Check for missing altsettings */ 658 /* Check for missing altsettings */
462 for (i = 0; i < nintf; ++i) { 659 for (i = 0; i < nintf; ++i) {
463 intfc = config->intf_cache[i]; 660 intfc = config->intf_cache[i];
464 for (j = 0; j < intfc->num_alt 661 for (j = 0; j < intfc->num_altsetting; ++j) {
465 for (n = 0; n < intfc- 662 for (n = 0; n < intfc->num_altsetting; ++n) {
466 if (intfc->alt 663 if (intfc->altsetting[n].desc.
467 bAlternate 664 bAlternateSetting == j)
468 break; 665 break;
469 } 666 }
470 if (n >= intfc->num_al 667 if (n >= intfc->num_altsetting)
471 dev_warn(ddev, 668 dev_warn(ddev, "config %d interface %d has no "
472 "altsettin 669 "altsetting %d\n", cfgno, inums[i], j);
473 } 670 }
474 } 671 }
475 672
476 return 0; 673 return 0;
477 } 674 }
478 675
479 /* hub-only!! ... and only exported for reset/ 676 /* hub-only!! ... and only exported for reset/reinit path.
480 * otherwise used internally on disconnect/des 677 * otherwise used internally on disconnect/destroy path
481 */ 678 */
482 void usb_destroy_configuration(struct usb_devi 679 void usb_destroy_configuration(struct usb_device *dev)
483 { 680 {
484 int c, i; 681 int c, i;
485 682
486 if (!dev->config) 683 if (!dev->config)
487 return; 684 return;
488 685
489 if (dev->rawdescriptors) { 686 if (dev->rawdescriptors) {
490 for (i = 0; i < dev->descripto 687 for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
491 kfree(dev->rawdescript 688 kfree(dev->rawdescriptors[i]);
492 689
493 kfree(dev->rawdescriptors); 690 kfree(dev->rawdescriptors);
494 dev->rawdescriptors = NULL; 691 dev->rawdescriptors = NULL;
495 } 692 }
496 693
497 for (c = 0; c < dev->descriptor.bNumCo 694 for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
498 struct usb_host_config *cf = & 695 struct usb_host_config *cf = &dev->config[c];
499 696
500 kfree(cf->string); 697 kfree(cf->string);
501 for (i = 0; i < cf->desc.bNumI 698 for (i = 0; i < cf->desc.bNumInterfaces; i++) {
502 if (cf->intf_cache[i]) 699 if (cf->intf_cache[i])
503 kref_put(&cf-> 700 kref_put(&cf->intf_cache[i]->ref,
504 usb_ 701 usb_release_interface_cache);
505 } 702 }
506 } 703 }
507 kfree(dev->config); 704 kfree(dev->config);
508 dev->config = NULL; 705 dev->config = NULL;
509 } 706 }
510 707
511 708
512 /* 709 /*
513 * Get the USB config descriptors, cache and p 710 * Get the USB config descriptors, cache and parse'em
514 * 711 *
515 * hub-only!! ... and only in reset path, or u 712 * hub-only!! ... and only in reset path, or usb_new_device()
516 * (used by real hubs and virtual root hubs) 713 * (used by real hubs and virtual root hubs)
517 * 714 *
518 * NOTE: if this is a WUSB device and is not a 715 * NOTE: if this is a WUSB device and is not authorized, we skip the
519 * whole thing. A non-authorized USB dev 716 * whole thing. A non-authorized USB device has no
520 * configurations. 717 * configurations.
521 */ 718 */
522 int usb_get_configuration(struct usb_device *d 719 int usb_get_configuration(struct usb_device *dev)
523 { 720 {
524 struct device *ddev = &dev->dev; 721 struct device *ddev = &dev->dev;
525 int ncfg = dev->descriptor.bNumConfigu 722 int ncfg = dev->descriptor.bNumConfigurations;
526 int result = 0; 723 int result = 0;
527 unsigned int cfgno, length; 724 unsigned int cfgno, length;
528 unsigned char *buffer; 725 unsigned char *buffer;
529 unsigned char *bigbuffer; 726 unsigned char *bigbuffer;
530 struct usb_config_descriptor *desc; 727 struct usb_config_descriptor *desc;
531 728
532 cfgno = 0; 729 cfgno = 0;
533 if (dev->authorized == 0) /* Not 730 if (dev->authorized == 0) /* Not really an error */
534 goto out_not_authorized; 731 goto out_not_authorized;
535 result = -ENOMEM; 732 result = -ENOMEM;
536 if (ncfg > USB_MAXCONFIG) { 733 if (ncfg > USB_MAXCONFIG) {
537 dev_warn(ddev, "too many confi 734 dev_warn(ddev, "too many configurations: %d, "
538 "using maximum allowed: %d 735 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
539 dev->descriptor.bNumConfigurat 736 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
540 } 737 }
541 738
542 if (ncfg < 1) { 739 if (ncfg < 1) {
543 dev_err(ddev, "no configuratio 740 dev_err(ddev, "no configurations\n");
544 return -EINVAL; 741 return -EINVAL;
545 } 742 }
546 743
547 length = ncfg * sizeof(struct usb_host 744 length = ncfg * sizeof(struct usb_host_config);
548 dev->config = kzalloc(length, GFP_KERN 745 dev->config = kzalloc(length, GFP_KERNEL);
549 if (!dev->config) 746 if (!dev->config)
550 goto err2; 747 goto err2;
551 748
552 length = ncfg * sizeof(char *); 749 length = ncfg * sizeof(char *);
553 dev->rawdescriptors = kzalloc(length, 750 dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
554 if (!dev->rawdescriptors) 751 if (!dev->rawdescriptors)
555 goto err2; 752 goto err2;
556 753
557 buffer = kmalloc(USB_DT_CONFIG_SIZE, G 754 buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
558 if (!buffer) 755 if (!buffer)
559 goto err2; 756 goto err2;
560 desc = (struct usb_config_descriptor * 757 desc = (struct usb_config_descriptor *)buffer;
561 758
562 result = 0; 759 result = 0;
563 for (; cfgno < ncfg; cfgno++) { 760 for (; cfgno < ncfg; cfgno++) {
564 /* We grab just the first desc 761 /* We grab just the first descriptor so we know how long
565 * the whole configuration is 762 * the whole configuration is */
566 result = usb_get_descriptor(de 763 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
567 buffer, USB_DT_CONFIG_SIZE 764 buffer, USB_DT_CONFIG_SIZE);
568 if (result < 0) { 765 if (result < 0) {
569 dev_err(ddev, "unable 766 dev_err(ddev, "unable to read config index %d "
570 "descriptor/%s: %d 767 "descriptor/%s: %d\n", cfgno, "start", result);
571 dev_err(ddev, "choppin 768 dev_err(ddev, "chopping to %d config(s)\n", cfgno);
572 dev->descriptor.bNumCo 769 dev->descriptor.bNumConfigurations = cfgno;
573 break; 770 break;
574 } else if (result < 4) { 771 } else if (result < 4) {
575 dev_err(ddev, "config 772 dev_err(ddev, "config index %d descriptor too short "
576 "(expected %i, got 773 "(expected %i, got %i)\n", cfgno,
577 USB_DT_CONFIG_SIZE 774 USB_DT_CONFIG_SIZE, result);
578 result = -EINVAL; 775 result = -EINVAL;
579 goto err; 776 goto err;
580 } 777 }
581 length = max((int) le16_to_cpu 778 length = max((int) le16_to_cpu(desc->wTotalLength),
582 USB_DT_CONFIG_SIZE); 779 USB_DT_CONFIG_SIZE);
583 780
584 /* Now that we know the length 781 /* Now that we know the length, get the whole thing */
585 bigbuffer = kmalloc(length, GF 782 bigbuffer = kmalloc(length, GFP_KERNEL);
586 if (!bigbuffer) { 783 if (!bigbuffer) {
587 result = -ENOMEM; 784 result = -ENOMEM;
588 goto err; 785 goto err;
589 } 786 }
590 result = usb_get_descriptor(de 787 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
591 bigbuffer, length); 788 bigbuffer, length);
592 if (result < 0) { 789 if (result < 0) {
593 dev_err(ddev, "unable 790 dev_err(ddev, "unable to read config index %d "
594 "descriptor/%s\n", 791 "descriptor/%s\n", cfgno, "all");
595 kfree(bigbuffer); 792 kfree(bigbuffer);
596 goto err; 793 goto err;
597 } 794 }
598 if (result < length) { 795 if (result < length) {
599 dev_warn(ddev, "config 796 dev_warn(ddev, "config index %d descriptor too short "
600 "(expected %i, got 797 "(expected %i, got %i)\n", cfgno, length, result);
601 length = result; 798 length = result;
602 } 799 }
603 800
604 dev->rawdescriptors[cfgno] = b 801 dev->rawdescriptors[cfgno] = bigbuffer;
605 802
606 result = usb_parse_configurati 803 result = usb_parse_configuration(&dev->dev, cfgno,
607 &dev->config[cfgno], bigbu 804 &dev->config[cfgno], bigbuffer, length);
608 if (result < 0) { 805 if (result < 0) {
609 ++cfgno; 806 ++cfgno;
610 goto err; 807 goto err;
611 } 808 }
612 } 809 }
613 result = 0; 810 result = 0;
614 811
615 err: 812 err:
616 kfree(buffer); 813 kfree(buffer);
617 out_not_authorized: 814 out_not_authorized:
618 dev->descriptor.bNumConfigurations = c 815 dev->descriptor.bNumConfigurations = cfgno;
619 err2: 816 err2:
620 if (result == -ENOMEM) 817 if (result == -ENOMEM)
621 dev_err(ddev, "out of memory\n 818 dev_err(ddev, "out of memory\n");
622 return result; 819 return result;
623 } 820 }
624 821
|
This page was automatically generated by the
LXR engine.
|