On Thu, Dec 31, 2020 at 06:04:00PM +0800, Peter Chen wrote: > On 20-12-29 14:44:43, Jack Pham wrote: > > From: Chandana Kishori Chiluveru <cchiluve@xxxxxxxxxxxxxx> > > > > When binding the ConfigFS gadget to a UDC, the functions in each > > configuration are added in list order. However, if usb_add_function() > > fails, the failed function is put back on its configuration's > > func_list and purge_configs_funcs() is called to further clean up. > > > > purge_configs_funcs() iterates over the configurations and functions > > in forward order, calling unbind() on each of the previously added > > functions. But after doing so, each function gets moved to the > > tail of the configuration's func_list. This results in reshuffling > > the original order of the functions within a configuration such > > that the failed function now appears first even though it may have > > originally appeared in the middle or even end of the list. At this > > point if the ConfigFS gadget is attempted to re-bind to the UDC, > > the functions will be added in a different order than intended, > > with the only recourse being to remove and relink the functions all > > over again. <snip> > Hi Jack, > > I am curious what features are broken if the functions are added with > not planned order? Hi Peter, This is mainly an issue for devices with functions that use vendor- specific instead of standard class/subclass IDs for their interface descriptors. Android ADB and Qualcomm QMI are a couple examples. So host interface drivers would only be able to install or bind based on matching VID/PID and interface position only. This is true for both Windows as well as Linux (see USB_DEVICE_INTERFACE_NUMBER). So if the gadget's function bind order gets jumbled up from the intended order, the resulting assigned interface numbers would be different and the host would not match its drivers to the correct interface. Instead we see the host driver gets bound but the endpoints it communicates with are wrong as they are for a completely different interface. Thanks, Jack -- The Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project