usb gadget: descriptor copying support
authorDavid Brownell <dbrownell@users.sourceforge.net>
Fri, 20 Jun 2008 00:52:25 +0000 (17:52 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 21 Jul 2008 22:16:00 +0000 (15:16 -0700)
commita4c39c41bf3592684e36fa0dbbd4ab1a31f969b9
tree548a902e3dc3999742fba83ff93c7584f995b73a
parenta7707adf9ee8de3c5b67e3793b98888f551ad00d
usb gadget: descriptor copying support

Define three new descriptor manipulation utilities, for use when
setting up functions that may have multiple instances:

usb_copy_descriptors() to copy a vector of descriptors
usb_free_descriptors() to free the copy
usb_find_endpoint() to find a copied version

These will be used as follows.  Functions will continue to have static
tables of descriptors they update, now used as __initdata templates.

When a function creates a new instance, it patches those tables with
relevant interface and string IDs, plus endpoint assignments.  Then it
copies those morphed descriptors, associates the copies with the new
function instance, and records the endpoint descriptors to use when
activating the endpoints.  When initialization is done, only the copies
remain in memory.  The copies are freed on driver removal.

This ensures that each instance has descriptors which hold the right
instance-specific data.  Two instances in the same configuration will
obviously never share the same interface IDs or use the same endpoints.
Instances in different configurations won't do so either, which means
this is slightly less memory-efficient in some cases.

This also includes a bugfix to the epautoconf code that shows up with
this usage model.  It must replace the previous endpoint number when
updating the template descriptors, not just mask in a few more bits.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/gadget/config.c
drivers/usb/gadget/epautoconf.c
include/linux/usb/gadget.h