2 #include <linux/usb/ch9.h>
3 #include <linux/module.h>
4 #include <linux/init.h>
5 #include <linux/slab.h>
6 #include <linux/device.h>
7 #include <asm/byteorder.h>
11 #define USB_MAXALTSETTING 128 /* Hard limit */
12 #define USB_MAXENDPOINTS 30 /* Hard limit */
14 #define USB_MAXCONFIG 8 /* Arbitrary limit */
17 static inline const char *plural(int n)
19 return (n == 1 ? "" : "s");
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)
26 struct usb_descriptor_header *h;
28 unsigned char *buffer0 = buffer;
30 /* Find the next descriptor of type dt1 or dt2 or dt3 */
32 h = (struct usb_descriptor_header *) buffer;
33 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2 ||
34 h->bDescriptorType == dt3)
41 /* Store the number of descriptors skipped and return the
42 * number of bytes skipped */
45 return buffer - buffer0;
48 static int find_next_descriptor(unsigned char *buffer, int size,
49 int dt1, int dt2, int *num_skipped)
51 struct usb_descriptor_header *h;
53 unsigned char *buffer0 = buffer;
55 /* Find the next descriptor of type dt1 or dt2 */
57 h = (struct usb_descriptor_header *) buffer;
58 if (h->bDescriptorType == dt1 || h->bDescriptorType == dt2)
65 /* Store the number of descriptors skipped and return the
66 * number of bytes skipped */
69 return buffer - buffer0;
72 static int usb_parse_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)
76 unsigned char *buffer_start = buffer;
77 struct usb_ep_comp_descriptor *desc;
83 /* Allocate space for the companion descriptor */
84 ep->ep_comp = kzalloc(sizeof(struct usb_host_ep_comp), GFP_KERNEL);
87 desc = (struct usb_ep_comp_descriptor *) buffer;
88 if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP) {
89 dev_warn(ddev, "No SuperSpeed endpoint companion for config %d "
90 " interface %d altsetting %d ep %d: "
91 "using minimum values\n",
92 cfgno, inum, asnum, ep->desc.bEndpointAddress);
93 ep->ep_comp->desc.bLength = USB_DT_EP_COMP_SIZE;
94 ep->ep_comp->desc.bDescriptorType = USB_DT_SS_ENDPOINT_COMP;
95 ep->ep_comp->desc.bMaxBurst = 0;
97 * Leave bmAttributes as zero, which will mean no streams for
98 * bulk, and isoc won't support multiple bursts of packets.
99 * With bursts of only one packet, and a Mult of 1, the max
100 * amount of data moved per endpoint service interval is one
103 if (usb_endpoint_xfer_isoc(&ep->desc) ||
104 usb_endpoint_xfer_int(&ep->desc))
105 ep->ep_comp->desc.wBytesPerInterval =
106 ep->desc.wMaxPacketSize;
108 * The next descriptor is for an Endpoint or Interface,
109 * no extra descriptors to copy into the companion structure,
110 * and we didn't eat up any of the buffer.
115 memcpy(&ep->ep_comp->desc, desc, USB_DT_EP_COMP_SIZE);
116 desc = &ep->ep_comp->desc;
117 buffer += desc->bLength;
118 size -= desc->bLength;
120 /* Eat up the other descriptors we don't care about */
121 ep->ep_comp->extra = buffer;
122 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
123 USB_DT_INTERFACE, &num_skipped);
124 ep->ep_comp->extralen = i;
127 retval = buffer - buffer_start + i;
129 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
130 num_skipped, plural(num_skipped),
131 "SuperSpeed endpoint companion");
133 /* Check the various values */
134 if (usb_endpoint_xfer_control(&ep->desc) && desc->bMaxBurst != 0) {
135 dev_warn(ddev, "Control endpoint with bMaxBurst = %d in "
136 "config %d interface %d altsetting %d ep %d: "
137 "setting to zero\n", desc->bMaxBurst,
138 cfgno, inum, asnum, ep->desc.bEndpointAddress);
141 if (desc->bMaxBurst > 15) {
142 dev_warn(ddev, "Endpoint with bMaxBurst = %d in "
143 "config %d interface %d altsetting %d ep %d: "
144 "setting to 15\n", desc->bMaxBurst,
145 cfgno, inum, asnum, ep->desc.bEndpointAddress);
146 desc->bMaxBurst = 15;
148 if ((usb_endpoint_xfer_control(&ep->desc) || usb_endpoint_xfer_int(&ep->desc))
149 && desc->bmAttributes != 0) {
150 dev_warn(ddev, "%s endpoint with bmAttributes = %d in "
151 "config %d interface %d altsetting %d ep %d: "
153 usb_endpoint_xfer_control(&ep->desc) ? "Control" : "Bulk",
155 cfgno, inum, asnum, ep->desc.bEndpointAddress);
156 desc->bmAttributes = 0;
158 if (usb_endpoint_xfer_bulk(&ep->desc) && desc->bmAttributes > 16) {
159 dev_warn(ddev, "Bulk endpoint with more than 65536 streams in "
160 "config %d interface %d altsetting %d ep %d: "
162 cfgno, inum, asnum, ep->desc.bEndpointAddress);
163 desc->bmAttributes = 16;
165 if (usb_endpoint_xfer_isoc(&ep->desc) && desc->bmAttributes > 2) {
166 dev_warn(ddev, "Isoc endpoint has Mult of %d in "
167 "config %d interface %d altsetting %d ep %d: "
168 "setting to 3\n", desc->bmAttributes + 1,
169 cfgno, inum, asnum, ep->desc.bEndpointAddress);
170 desc->bmAttributes = 2;
172 if (usb_endpoint_xfer_isoc(&ep->desc)) {
173 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1) *
174 (desc->bmAttributes + 1);
175 } else if (usb_endpoint_xfer_int(&ep->desc)) {
176 max_tx = ep->desc.wMaxPacketSize * (desc->bMaxBurst + 1);
180 if (desc->wBytesPerInterval > max_tx) {
181 dev_warn(ddev, "%s endpoint with wBytesPerInterval of %d in "
182 "config %d interface %d altsetting %d ep %d: "
184 usb_endpoint_xfer_isoc(&ep->desc) ? "Isoc" : "Int",
185 desc->wBytesPerInterval,
186 cfgno, inum, asnum, ep->desc.bEndpointAddress,
188 desc->wBytesPerInterval = max_tx;
194 static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
195 int asnum, struct usb_host_interface *ifp, int num_ep,
196 unsigned char *buffer, int size)
198 unsigned char *buffer0 = buffer;
199 struct usb_endpoint_descriptor *d;
200 struct usb_host_endpoint *endpoint;
203 d = (struct usb_endpoint_descriptor *) buffer;
204 buffer += d->bLength;
207 if (d->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE)
208 n = USB_DT_ENDPOINT_AUDIO_SIZE;
209 else if (d->bLength >= USB_DT_ENDPOINT_SIZE)
210 n = USB_DT_ENDPOINT_SIZE;
212 dev_warn(ddev, "config %d interface %d altsetting %d has an "
213 "invalid endpoint descriptor of length %d, skipping\n",
214 cfgno, inum, asnum, d->bLength);
215 goto skip_to_next_endpoint_or_interface_descriptor;
218 i = d->bEndpointAddress & ~USB_ENDPOINT_DIR_MASK;
219 if (i >= 16 || i == 0) {
220 dev_warn(ddev, "config %d interface %d altsetting %d has an "
221 "invalid endpoint with address 0x%X, skipping\n",
222 cfgno, inum, asnum, d->bEndpointAddress);
223 goto skip_to_next_endpoint_or_interface_descriptor;
226 /* Only store as many endpoints as we have room for */
227 if (ifp->desc.bNumEndpoints >= num_ep)
228 goto skip_to_next_endpoint_or_interface_descriptor;
230 endpoint = &ifp->endpoint[ifp->desc.bNumEndpoints];
231 ++ifp->desc.bNumEndpoints;
233 memcpy(&endpoint->desc, d, n);
234 INIT_LIST_HEAD(&endpoint->urb_list);
236 /* Fix up bInterval values outside the legal range. Use 32 ms if no
237 * proper value can be guessed. */
238 i = 0; /* i = min, j = max, n = default */
240 if (usb_endpoint_xfer_int(d)) {
242 switch (to_usb_device(ddev)->speed) {
243 case USB_SPEED_SUPER:
245 /* Many device manufacturers are using full-speed
246 * bInterval values in high-speed interrupt endpoint
247 * descriptors. Try to fix those and fall back to a
248 * 32 ms default value otherwise. */
249 n = fls(d->bInterval*8);
251 n = 9; /* 32 ms = 2^(9-1) uframes */
254 default: /* USB_SPEED_FULL or _LOW */
255 /* For low-speed, 10 ms is the official minimum.
256 * But some "overclocked" devices might want faster
257 * polling so we'll allow it. */
261 } else if (usb_endpoint_xfer_isoc(d)) {
264 switch (to_usb_device(ddev)->speed) {
266 n = 9; /* 32 ms = 2^(9-1) uframes */
268 default: /* USB_SPEED_FULL */
269 n = 6; /* 32 ms = 2^(6-1) frames */
273 if (d->bInterval < i || d->bInterval > j) {
274 dev_warn(ddev, "config %d interface %d altsetting %d "
275 "endpoint 0x%X has an invalid bInterval %d, "
278 d->bEndpointAddress, d->bInterval, n);
279 endpoint->desc.bInterval = n;
282 /* Some buggy low-speed devices have Bulk endpoints, which is
283 * explicitly forbidden by the USB spec. In an attempt to make
284 * them usable, we will try treating them as Interrupt endpoints.
286 if (to_usb_device(ddev)->speed == USB_SPEED_LOW &&
287 usb_endpoint_xfer_bulk(d)) {
288 dev_warn(ddev, "config %d interface %d altsetting %d "
289 "endpoint 0x%X is Bulk; changing to Interrupt\n",
290 cfgno, inum, asnum, d->bEndpointAddress);
291 endpoint->desc.bmAttributes = USB_ENDPOINT_XFER_INT;
292 endpoint->desc.bInterval = 1;
293 if (le16_to_cpu(endpoint->desc.wMaxPacketSize) > 8)
294 endpoint->desc.wMaxPacketSize = cpu_to_le16(8);
298 * Some buggy high speed devices have bulk endpoints using
299 * maxpacket sizes other than 512. High speed HCDs may not
300 * be able to handle that particular bug, so let's warn...
302 if (to_usb_device(ddev)->speed == USB_SPEED_HIGH
303 && usb_endpoint_xfer_bulk(d)) {
306 maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize) & 0x07ff;
308 dev_warn(ddev, "config %d interface %d altsetting %d "
309 "bulk endpoint 0x%X has invalid maxpacket %d\n",
310 cfgno, inum, asnum, d->bEndpointAddress,
313 /* Allocate room for and parse any endpoint companion descriptors */
314 if (to_usb_device(ddev)->speed == USB_SPEED_SUPER) {
315 endpoint->extra = buffer;
316 i = find_next_descriptor_more(buffer, size, USB_DT_SS_ENDPOINT_COMP,
317 USB_DT_ENDPOINT, USB_DT_INTERFACE, &n);
318 endpoint->extralen = i;
323 retval = usb_parse_endpoint_companion(ddev, cfgno, inum, asnum,
324 endpoint, num_ep, buffer, size);
327 retval = buffer - buffer0;
330 retval = buffer - buffer0;
333 /* Skip over any Class Specific or Vendor Specific descriptors;
334 * find the next endpoint or interface descriptor */
335 endpoint->extra = buffer;
336 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
337 USB_DT_INTERFACE, &n);
338 endpoint->extralen = i;
339 retval = buffer - buffer0 + i;
342 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
343 n, plural(n), "endpoint");
346 skip_to_next_endpoint_or_interface_descriptor:
347 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
348 USB_DT_INTERFACE, NULL);
349 return buffer - buffer0 + i;
352 void usb_release_interface_cache(struct kref *ref)
354 struct usb_interface_cache *intfc = ref_to_usb_interface_cache(ref);
357 for (j = 0; j < intfc->num_altsetting; j++) {
358 struct usb_host_interface *alt = &intfc->altsetting[j];
360 kfree(alt->endpoint);
366 static int usb_parse_interface(struct device *ddev, int cfgno,
367 struct usb_host_config *config, unsigned char *buffer, int size,
368 u8 inums[], u8 nalts[])
370 unsigned char *buffer0 = buffer;
371 struct usb_interface_descriptor *d;
373 struct usb_interface_cache *intfc;
374 struct usb_host_interface *alt;
377 int num_ep, num_ep_orig;
379 d = (struct usb_interface_descriptor *) buffer;
380 buffer += d->bLength;
383 if (d->bLength < USB_DT_INTERFACE_SIZE)
384 goto skip_to_next_interface_descriptor;
386 /* Which interface entry is this? */
388 inum = d->bInterfaceNumber;
389 for (i = 0; i < config->desc.bNumInterfaces; ++i) {
390 if (inums[i] == inum) {
391 intfc = config->intf_cache[i];
395 if (!intfc || intfc->num_altsetting >= nalts[i])
396 goto skip_to_next_interface_descriptor;
398 /* Check for duplicate altsetting entries */
399 asnum = d->bAlternateSetting;
400 for ((i = 0, alt = &intfc->altsetting[0]);
401 i < intfc->num_altsetting;
403 if (alt->desc.bAlternateSetting == asnum) {
404 dev_warn(ddev, "Duplicate descriptor for config %d "
405 "interface %d altsetting %d, skipping\n",
407 goto skip_to_next_interface_descriptor;
411 ++intfc->num_altsetting;
412 memcpy(&alt->desc, d, USB_DT_INTERFACE_SIZE);
414 /* Skip over any Class Specific or Vendor Specific descriptors;
415 * find the first endpoint or interface descriptor */
417 i = find_next_descriptor(buffer, size, USB_DT_ENDPOINT,
418 USB_DT_INTERFACE, &n);
421 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
422 n, plural(n), "interface");
426 /* Allocate space for the right(?) number of endpoints */
427 num_ep = num_ep_orig = alt->desc.bNumEndpoints;
428 alt->desc.bNumEndpoints = 0; /* Use as a counter */
429 if (num_ep > USB_MAXENDPOINTS) {
430 dev_warn(ddev, "too many endpoints for config %d interface %d "
431 "altsetting %d: %d, using maximum allowed: %d\n",
432 cfgno, inum, asnum, num_ep, USB_MAXENDPOINTS);
433 num_ep = USB_MAXENDPOINTS;
437 /* Can't allocate 0 bytes */
438 len = sizeof(struct usb_host_endpoint) * num_ep;
439 alt->endpoint = kzalloc(len, GFP_KERNEL);
444 /* Parse all the endpoint descriptors */
447 if (((struct usb_descriptor_header *) buffer)->bDescriptorType
450 retval = usb_parse_endpoint(ddev, cfgno, inum, asnum, alt,
451 num_ep, buffer, size);
460 if (n != num_ep_orig)
461 dev_warn(ddev, "config %d interface %d altsetting %d has %d "
462 "endpoint descriptor%s, different from the interface "
463 "descriptor's value: %d\n",
464 cfgno, inum, asnum, n, plural(n), num_ep_orig);
465 return buffer - buffer0;
467 skip_to_next_interface_descriptor:
468 i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
469 USB_DT_INTERFACE, NULL);
470 return buffer - buffer0 + i;
473 static int usb_parse_configuration(struct device *ddev, int cfgidx,
474 struct usb_host_config *config, unsigned char *buffer, int size)
476 unsigned char *buffer0 = buffer;
478 int nintf, nintf_orig;
480 struct usb_interface_cache *intfc;
481 unsigned char *buffer2;
483 struct usb_descriptor_header *header;
485 u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
486 unsigned iad_num = 0;
488 memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
489 if (config->desc.bDescriptorType != USB_DT_CONFIG ||
490 config->desc.bLength < USB_DT_CONFIG_SIZE) {
491 dev_err(ddev, "invalid descriptor for config index %d: "
492 "type = 0x%X, length = %d\n", cfgidx,
493 config->desc.bDescriptorType, config->desc.bLength);
496 cfgno = config->desc.bConfigurationValue;
498 buffer += config->desc.bLength;
499 size -= config->desc.bLength;
501 nintf = nintf_orig = config->desc.bNumInterfaces;
502 if (nintf > USB_MAXINTERFACES) {
503 dev_warn(ddev, "config %d has too many interfaces: %d, "
504 "using maximum allowed: %d\n",
505 cfgno, nintf, USB_MAXINTERFACES);
506 nintf = USB_MAXINTERFACES;
509 /* Go through the descriptors, checking their length and counting the
510 * number of altsettings for each interface */
512 for ((buffer2 = buffer, size2 = size);
514 (buffer2 += header->bLength, size2 -= header->bLength)) {
516 if (size2 < sizeof(struct usb_descriptor_header)) {
517 dev_warn(ddev, "config %d descriptor has %d excess "
518 "byte%s, ignoring\n",
519 cfgno, size2, plural(size2));
523 header = (struct usb_descriptor_header *) buffer2;
524 if ((header->bLength > size2) || (header->bLength < 2)) {
525 dev_warn(ddev, "config %d has an invalid descriptor "
526 "of length %d, skipping remainder of the config\n",
527 cfgno, header->bLength);
531 if (header->bDescriptorType == USB_DT_INTERFACE) {
532 struct usb_interface_descriptor *d;
535 d = (struct usb_interface_descriptor *) header;
536 if (d->bLength < USB_DT_INTERFACE_SIZE) {
537 dev_warn(ddev, "config %d has an invalid "
538 "interface descriptor of length %d, "
539 "skipping\n", cfgno, d->bLength);
543 inum = d->bInterfaceNumber;
544 if (inum >= nintf_orig)
545 dev_warn(ddev, "config %d has an invalid "
546 "interface number: %d but max is %d\n",
547 cfgno, inum, nintf_orig - 1);
549 /* Have we already encountered this interface?
550 * Count its altsettings */
551 for (i = 0; i < n; ++i) {
552 if (inums[i] == inum)
558 } else if (n < USB_MAXINTERFACES) {
564 } else if (header->bDescriptorType ==
565 USB_DT_INTERFACE_ASSOCIATION) {
566 if (iad_num == USB_MAXIADS) {
567 dev_warn(ddev, "found more Interface "
568 "Association Descriptors "
569 "than allocated for in "
570 "configuration %d\n", cfgno);
572 config->intf_assoc[iad_num] =
573 (struct usb_interface_assoc_descriptor
578 } else if (header->bDescriptorType == USB_DT_DEVICE ||
579 header->bDescriptorType == USB_DT_CONFIG)
580 dev_warn(ddev, "config %d contains an unexpected "
581 "descriptor of type 0x%X, skipping\n",
582 cfgno, header->bDescriptorType);
584 } /* for ((buffer2 = buffer, size2 = size); ...) */
585 size = buffer2 - buffer;
586 config->desc.wTotalLength = cpu_to_le16(buffer2 - buffer0);
589 dev_warn(ddev, "config %d has %d interface%s, different from "
590 "the descriptor's value: %d\n",
591 cfgno, n, plural(n), nintf_orig);
593 dev_warn(ddev, "config %d has no interfaces?\n", cfgno);
594 config->desc.bNumInterfaces = nintf = n;
596 /* Check for missing interface numbers */
597 for (i = 0; i < nintf; ++i) {
598 for (j = 0; j < nintf; ++j) {
603 dev_warn(ddev, "config %d has no interface number "
607 /* Allocate the usb_interface_caches and altsetting arrays */
608 for (i = 0; i < nintf; ++i) {
610 if (j > USB_MAXALTSETTING) {
611 dev_warn(ddev, "too many alternate settings for "
612 "config %d interface %d: %d, "
613 "using maximum allowed: %d\n",
614 cfgno, inums[i], j, USB_MAXALTSETTING);
615 nalts[i] = j = USB_MAXALTSETTING;
618 len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
619 config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
622 kref_init(&intfc->ref);
625 /* FIXME: parse the BOS descriptor */
627 /* Skip over any Class Specific or Vendor Specific descriptors;
628 * find the first interface descriptor */
629 config->extra = buffer;
630 i = find_next_descriptor(buffer, size, USB_DT_INTERFACE,
631 USB_DT_INTERFACE, &n);
632 config->extralen = i;
634 dev_dbg(ddev, "skipped %d descriptor%s after %s\n",
635 n, plural(n), "configuration");
639 /* Parse all the interface/altsetting descriptors */
641 retval = usb_parse_interface(ddev, cfgno, config,
642 buffer, size, inums, nalts);
650 /* Check for missing altsettings */
651 for (i = 0; i < nintf; ++i) {
652 intfc = config->intf_cache[i];
653 for (j = 0; j < intfc->num_altsetting; ++j) {
654 for (n = 0; n < intfc->num_altsetting; ++n) {
655 if (intfc->altsetting[n].desc.
656 bAlternateSetting == j)
659 if (n >= intfc->num_altsetting)
660 dev_warn(ddev, "config %d interface %d has no "
661 "altsetting %d\n", cfgno, inums[i], j);
668 /* hub-only!! ... and only exported for reset/reinit path.
669 * otherwise used internally on disconnect/destroy path
671 void usb_destroy_configuration(struct usb_device *dev)
678 if (dev->rawdescriptors) {
679 for (i = 0; i < dev->descriptor.bNumConfigurations; i++)
680 kfree(dev->rawdescriptors[i]);
682 kfree(dev->rawdescriptors);
683 dev->rawdescriptors = NULL;
686 for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
687 struct usb_host_config *cf = &dev->config[c];
690 for (i = 0; i < cf->desc.bNumInterfaces; i++) {
691 if (cf->intf_cache[i])
692 kref_put(&cf->intf_cache[i]->ref,
693 usb_release_interface_cache);
702 * Get the USB config descriptors, cache and parse'em
704 * hub-only!! ... and only in reset path, or usb_new_device()
705 * (used by real hubs and virtual root hubs)
707 * NOTE: if this is a WUSB device and is not authorized, we skip the
708 * whole thing. A non-authorized USB device has no
711 int usb_get_configuration(struct usb_device *dev)
713 struct device *ddev = &dev->dev;
714 int ncfg = dev->descriptor.bNumConfigurations;
716 unsigned int cfgno, length;
717 unsigned char *buffer;
718 unsigned char *bigbuffer;
719 struct usb_config_descriptor *desc;
722 if (dev->authorized == 0) /* Not really an error */
723 goto out_not_authorized;
725 if (ncfg > USB_MAXCONFIG) {
726 dev_warn(ddev, "too many configurations: %d, "
727 "using maximum allowed: %d\n", ncfg, USB_MAXCONFIG);
728 dev->descriptor.bNumConfigurations = ncfg = USB_MAXCONFIG;
732 dev_err(ddev, "no configurations\n");
736 length = ncfg * sizeof(struct usb_host_config);
737 dev->config = kzalloc(length, GFP_KERNEL);
741 length = ncfg * sizeof(char *);
742 dev->rawdescriptors = kzalloc(length, GFP_KERNEL);
743 if (!dev->rawdescriptors)
746 buffer = kmalloc(USB_DT_CONFIG_SIZE, GFP_KERNEL);
749 desc = (struct usb_config_descriptor *)buffer;
752 for (; cfgno < ncfg; cfgno++) {
753 /* We grab just the first descriptor so we know how long
754 * the whole configuration is */
755 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
756 buffer, USB_DT_CONFIG_SIZE);
758 dev_err(ddev, "unable to read config index %d "
759 "descriptor/%s: %d\n", cfgno, "start", result);
760 dev_err(ddev, "chopping to %d config(s)\n", cfgno);
761 dev->descriptor.bNumConfigurations = cfgno;
763 } else if (result < 4) {
764 dev_err(ddev, "config index %d descriptor too short "
765 "(expected %i, got %i)\n", cfgno,
766 USB_DT_CONFIG_SIZE, result);
770 length = max((int) le16_to_cpu(desc->wTotalLength),
773 /* Now that we know the length, get the whole thing */
774 bigbuffer = kmalloc(length, GFP_KERNEL);
779 result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno,
782 dev_err(ddev, "unable to read config index %d "
783 "descriptor/%s\n", cfgno, "all");
787 if (result < length) {
788 dev_warn(ddev, "config index %d descriptor too short "
789 "(expected %i, got %i)\n", cfgno, length, result);
793 dev->rawdescriptors[cfgno] = bigbuffer;
795 result = usb_parse_configuration(&dev->dev, cfgno,
796 &dev->config[cfgno], bigbuffer, length);
807 dev->descriptor.bNumConfigurations = cfgno;
809 if (result == -ENOMEM)
810 dev_err(ddev, "out of memory\n");