]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
usb: gadget: f_tcm: Fix Get/SetInterface return value
authorThinh Nguyen <Thinh.Nguyen@synopsys.com>
Wed, 11 Dec 2024 00:31:55 +0000 (00:31 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:46:59 +0000 (12:46 +0100)
commit 3b997089903b909684114aca6f79d683e5c64a0e upstream.

Check to make sure that the GetInterface and SetInterface are for valid
interface. Return proper alternate setting number on GetInterface.

Fixes: 0b8b1a1fede0 ("usb: gadget: f_tcm: Provide support to get alternate setting in tcm function")
Cc: stable@vger.kernel.org
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/ffd91b4640945ea4d3b4f4091cf1abbdbd9cf4fc.1733876548.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/gadget/function/f_tcm.c

index 5a2e9ce2bc352e3182c17b96bad3d80d574ff1a4..51e7788f2cd2b1abe2f9e0942020a31fb97ec736 100644 (file)
@@ -2102,9 +2102,14 @@ static void tcm_delayed_set_alt(struct work_struct *wq)
 
 static int tcm_get_alt(struct usb_function *f, unsigned intf)
 {
-       if (intf == bot_intf_desc.bInterfaceNumber)
+       struct f_uas *fu = to_f_uas(f);
+
+       if (fu->iface != intf)
+               return -EOPNOTSUPP;
+
+       if (fu->flags & USBG_IS_BOT)
                return USB_G_ALT_INT_BBB;
-       if (intf == uasp_intf_desc.bInterfaceNumber)
+       else if (fu->flags & USBG_IS_UAS)
                return USB_G_ALT_INT_UAS;
 
        return -EOPNOTSUPP;
@@ -2114,6 +2119,9 @@ static int tcm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
 {
        struct f_uas *fu = to_f_uas(f);
 
+       if (fu->iface != intf)
+               return -EOPNOTSUPP;
+
        if ((alt == USB_G_ALT_INT_BBB) || (alt == USB_G_ALT_INT_UAS)) {
                struct guas_setup_wq *work;