Commit f33e6eab authored by Thinh Nguyen's avatar Thinh Nguyen Committed by Wentao Guan
Browse files

usb: gadget: f_tcm: Fix Get/SetInterface return value

stable inclusion
from stable-v6.6.76
commit 0e7fc92a0572d9be2ad1633de81dedfad69f3d84
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBW08Q

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=0e7fc92a0572d9be2ad1633de81dedfad69f3d84



--------------------------------

commit 3b997089903b909684114aca6f79d683e5c64a0e upstream.

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

Fixes: 0b8b1a1f ("usb: gadget: f_tcm: Provide support to get alternate setting in tcm function")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarThinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/ffd91b4640945ea4d3b4f4091cf1abbdbd9cf4fc.1733876548.git.Thinh.Nguyen@synopsys.com


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 0e7fc92a0572d9be2ad1633de81dedfad69f3d84)
Signed-off-by: default avatarWentao Guan <guanwentao@uniontech.com>
parent 6527f022
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2048,9 +2048,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;
@@ -2060,6 +2065,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;