Commit 43345b84 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

[PATCH] USB: Changes to core/config.c (4 of 9)

Although it's hard to tell from reading the patch, this just moves one
section of code to a slightly different spot.  Currently the code that
skips over the extra class- and vendor-specific configuration-related
descriptors is part of the loop that parses interface descriptors.  The
patch moves it outside, immediately before that loop -- where it belongs.
parent 580d2f45
...@@ -251,8 +251,10 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer) ...@@ -251,8 +251,10 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer)
int nintf; int nintf;
int i, size; int i, size;
struct usb_interface *interface; struct usb_interface *interface;
int retval; int numskipped, len;
char *begin;
struct usb_descriptor_header *header; struct usb_descriptor_header *header;
int retval;
memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE); memcpy(&config->desc, buffer, USB_DT_CONFIG_SIZE);
le16_to_cpus(&config->desc.wTotalLength); le16_to_cpus(&config->desc.wTotalLength);
...@@ -284,55 +286,48 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer) ...@@ -284,55 +286,48 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer)
buffer += config->desc.bLength; buffer += config->desc.bLength;
size -= config->desc.bLength; size -= config->desc.bLength;
for (i = 0; i < nintf; i++) { /* Skip over any Class Specific or Vendor Specific descriptors */
int numskipped, len; begin = buffer;
char *begin; numskipped = 0;
while (size >= sizeof(struct usb_descriptor_header)) {
header = (struct usb_descriptor_header *)buffer;
/* Skip over the rest of the Class Specific or Vendor */ if ((header->bLength > size) || (header->bLength < 2)) {
/* Specific descriptors */ err("invalid descriptor length of %d", header->bLength);
begin = buffer; return -EINVAL;
numskipped = 0; }
while (size >= sizeof(struct usb_descriptor_header)) {
header = (struct usb_descriptor_header *)buffer;
if ((header->bLength > size) || (header->bLength < 2)) { /* If we find another "proper" descriptor then we're done */
err("invalid descriptor length of %d", header->bLength); if ((header->bDescriptorType == USB_DT_ENDPOINT) ||
return -EINVAL; (header->bDescriptorType == USB_DT_INTERFACE) ||
} (header->bDescriptorType == USB_DT_CONFIG) ||
(header->bDescriptorType == USB_DT_DEVICE))
break;
/* If we find another "proper" descriptor then we're done */ dbg("skipping descriptor 0x%X", header->bDescriptorType);
if ((header->bDescriptorType == USB_DT_ENDPOINT) || numskipped++;
(header->bDescriptorType == USB_DT_INTERFACE) ||
(header->bDescriptorType == USB_DT_CONFIG) ||
(header->bDescriptorType == USB_DT_DEVICE))
break;
dbg("skipping descriptor 0x%X", header->bDescriptorType); buffer += header->bLength;
numskipped++; size -= header->bLength;
}
if (numskipped) {
dbg("skipped %d class/vendor specific configuration descriptors", numskipped);
buffer += header->bLength; /* Copy any unknown descriptors into a storage area for */
size -= header->bLength; /* drivers to later parse */
len = buffer - begin;
config->extra = kmalloc(len, GFP_KERNEL);
if (!config->extra) {
err("couldn't allocate memory for config extra descriptors");
return -ENOMEM;
} }
if (numskipped) {
dbg("skipped %d class/vendor specific configuration descriptors", numskipped);
/* Copy any unknown descriptors into a storage area for */ memcpy(config->extra, begin, len);
/* drivers to later parse */ config->extralen = len;
len = buffer - begin; }
if (config->extralen) {
warn("extra config descriptor");
} else {
config->extra = kmalloc(len, GFP_KERNEL);
if (!config->extra) {
err("couldn't allocate memory for config extra descriptors");
return -ENOMEM;
}
memcpy(config->extra, begin, len);
config->extralen = len;
}
}
/* Parse all the interface/altsetting descriptors */
for (i = 0; i < nintf; i++) {
retval = usb_parse_interface(config->interface[i], buffer, size); retval = usb_parse_interface(config->interface[i], buffer, size);
if (retval < 0) if (retval < 0)
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment