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

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

This patch implements the change discussed last weekend.  Rather than
allocating separate memory areas for the "extra" descriptors and copying
the descriptor contents, it simply makes the "extra" pointers refer to
memory within the rawdescriptor arrays.
parent 69d7ab7d
...@@ -17,7 +17,7 @@ static int usb_parse_endpoint(struct usb_host_endpoint *endpoint, unsigned char ...@@ -17,7 +17,7 @@ static int usb_parse_endpoint(struct usb_host_endpoint *endpoint, unsigned char
unsigned char *buffer0 = buffer; unsigned char *buffer0 = buffer;
struct usb_descriptor_header *header; struct usb_descriptor_header *header;
unsigned char *begin; unsigned char *begin;
int len, numskipped; int numskipped;
header = (struct usb_descriptor_header *)buffer; header = (struct usb_descriptor_header *)buffer;
if (header->bDescriptorType != USB_DT_ENDPOINT) { if (header->bDescriptorType != USB_DT_ENDPOINT) {
...@@ -65,19 +65,8 @@ static int usb_parse_endpoint(struct usb_host_endpoint *endpoint, unsigned char ...@@ -65,19 +65,8 @@ static int usb_parse_endpoint(struct usb_host_endpoint *endpoint, unsigned char
} }
if (numskipped) { if (numskipped) {
dbg("skipped %d class/vendor specific endpoint descriptors", numskipped); dbg("skipped %d class/vendor specific endpoint descriptors", numskipped);
endpoint->extra = begin;
/* Copy any unknown descriptors into a storage area for drivers */ endpoint->extralen = buffer - begin;
/* to later parse */
len = buffer - begin;
endpoint->extra = kmalloc(len, GFP_KERNEL);
if (!endpoint->extra) {
err("couldn't allocate memory for endpoint extra descriptors");
return -ENOMEM;
}
memcpy(endpoint->extra, begin, len);
endpoint->extralen = len;
} }
return buffer - buffer0; return buffer - buffer0;
...@@ -87,22 +76,14 @@ static void usb_release_intf(struct device *dev) ...@@ -87,22 +76,14 @@ static void usb_release_intf(struct device *dev)
{ {
struct usb_interface *intf; struct usb_interface *intf;
int j; int j;
int k;
intf = to_usb_interface(dev); intf = to_usb_interface(dev);
if (intf->altsetting) { if (intf->altsetting) {
for (j = 0; j < intf->num_altsetting; j++) { for (j = 0; j < intf->num_altsetting; j++) {
struct usb_host_interface *as = &intf->altsetting[j]; struct usb_host_interface *as = &intf->altsetting[j];
if (as->extra)
kfree(as->extra); kfree(as->endpoint);
if (as->endpoint) {
for (k = 0; k < as->desc.bNumEndpoints; k++)
if (as->endpoint[k].extra)
kfree(as->endpoint[k].extra);
kfree(as->endpoint);
}
} }
kfree(intf->altsetting); kfree(intf->altsetting);
} }
...@@ -183,18 +164,8 @@ static int usb_parse_interface(struct usb_host_config *config, unsigned char *bu ...@@ -183,18 +164,8 @@ static int usb_parse_interface(struct usb_host_config *config, unsigned char *bu
} }
if (numskipped) { if (numskipped) {
dbg("skipped %d class/vendor specific interface descriptors", numskipped); dbg("skipped %d class/vendor specific interface descriptors", numskipped);
ifp->extra = begin;
/* Copy any unknown descriptors into a storage area for */ ifp->extralen = buffer - begin;
/* drivers to later parse */
len = buffer - begin;
ifp->extra = kmalloc(len, GFP_KERNEL);
if (!ifp->extra) {
err("couldn't allocate memory for interface extra descriptors");
return -ENOMEM;
}
memcpy(ifp->extra, begin, len);
ifp->extralen = len;
} }
if (ifp->desc.bNumEndpoints > USB_MAXENDPOINTS) { if (ifp->desc.bNumEndpoints > USB_MAXENDPOINTS) {
...@@ -355,18 +326,8 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer, int si ...@@ -355,18 +326,8 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer, int si
} }
if (numskipped) { if (numskipped) {
dbg("skipped %d class/vendor specific configuration descriptors", numskipped); dbg("skipped %d class/vendor specific configuration descriptors", numskipped);
config->extra = begin;
/* Copy any unknown descriptors into a storage area for */ config->extralen = buffer - begin;
/* 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;
}
memcpy(config->extra, begin, len);
config->extralen = len;
} }
/* Parse all the interface/altsetting descriptors */ /* Parse all the interface/altsetting descriptors */
...@@ -418,7 +379,6 @@ void usb_destroy_configuration(struct usb_device *dev) ...@@ -418,7 +379,6 @@ void usb_destroy_configuration(struct usb_device *dev)
if (ifp) if (ifp)
put_device(&ifp->dev); put_device(&ifp->dev);
} }
kfree(cf->extra);
} }
kfree(dev->config); kfree(dev->config);
} }
......
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