Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: configfs: Correctly set use_os_string at bind

Once the use_os_string flag is set to true for some functions
(e.g. adb/mtp) which need to response the OS string, and then
if we re-bind the ConfigFS gadget to use the other functions
(e.g. hid) which should not to response the OS string, however,
because the use_os_string flag is still true, so the usb gadget
response the OS string descriptor incorrectly, this can cause
the USB device to be unrecognizable on the Windows system.

An example of this as follows:

echo 1 > os_desc/use
ln -s functions/ffs.adb configs/b.1/function0
start adbd
echo "<udc device>" > UDC #succeed

stop adbd
rm configs/b.1/function0
echo 0 > os_desc/use
ln -s functions/hid.gs0 configs/b.1/function0
echo "<udc device>" > UDC #fail to connect on Windows

This patch sets the use_os_string flag to false at bind if
the functions not support OS Descriptors.

Signed-off-by: William Wu <william.wu@rock-chips.com>
Fixes: 87213d388e92 ("usb: gadget: configfs: OS String support")
Link: https://lore.kernel.org/r/1755833769-25434-1-git-send-email-william.wu@rock-chips.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

William Wu and committed by
Greg Kroah-Hartman
e271cc0d ab967169

+2
+2
drivers/usb/gadget/configfs.c
··· 1750 1750 cdev->use_os_string = true; 1751 1751 cdev->b_vendor_code = gi->b_vendor_code; 1752 1752 memcpy(cdev->qw_sign, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 1753 + } else { 1754 + cdev->use_os_string = false; 1753 1755 } 1754 1756 1755 1757 if (gadget_is_otg(gadget) && !otg_desc[0]) {