ChangeSet 1.1315.8.29, 2003/09/18 14:33:50-07:00, stern@rowland.harvard.edu [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. drivers/usb/core/config.c | 56 ++++++---------------------------------------- 1 files changed, 8 insertions(+), 48 deletions(-) diff -Nru a/drivers/usb/core/config.c b/drivers/usb/core/config.c --- a/drivers/usb/core/config.c Fri Sep 19 17:08:22 2003 +++ b/drivers/usb/core/config.c Fri Sep 19 17:08:22 2003 @@ -17,7 +17,7 @@ unsigned char *buffer0 = buffer; struct usb_descriptor_header *header; unsigned char *begin; - int len, numskipped; + int numskipped; header = (struct usb_descriptor_header *)buffer; if (header->bDescriptorType != USB_DT_ENDPOINT) { @@ -65,19 +65,8 @@ } if (numskipped) { dbg("skipped %d class/vendor specific endpoint descriptors", numskipped); - - /* Copy any unknown descriptors into a storage area for drivers */ - /* 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; + endpoint->extra = begin; + endpoint->extralen = buffer - begin; } return buffer - buffer0; @@ -87,22 +76,14 @@ { struct usb_interface *intf; int j; - int k; intf = to_usb_interface(dev); if (intf->altsetting) { for (j = 0; j < intf->num_altsetting; j++) { struct usb_host_interface *as = &intf->altsetting[j]; - if (as->extra) - kfree(as->extra); - 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(as->endpoint); } kfree(intf->altsetting); } @@ -183,18 +164,8 @@ } if (numskipped) { dbg("skipped %d class/vendor specific interface descriptors", numskipped); - - /* Copy any unknown descriptors into a storage area for */ - /* 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; + ifp->extra = begin; + ifp->extralen = buffer - begin; } if (ifp->desc.bNumEndpoints > USB_MAXENDPOINTS) { @@ -355,18 +326,8 @@ } if (numskipped) { dbg("skipped %d class/vendor specific configuration descriptors", numskipped); - - /* Copy any unknown descriptors into a storage area for */ - /* 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; + config->extra = begin; + config->extralen = buffer - begin; } /* Parse all the interface/altsetting descriptors */ @@ -418,7 +379,6 @@ if (ifp) put_device(&ifp->dev); } - kfree(cf->extra); } kfree(dev->config); }