Skip to content

Commit

Permalink
usb: gadget: f_tcm: Stall on invalid CBW
Browse files Browse the repository at this point in the history
If the BOT command CBW is invalid, make sure to respond by setting
status endpoint STALL until the next proper CBW or reset.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/96022e2d5225f01a20263a4ba9c2e2c8a63328b8.1733876548.git.Thinh.Nguyen@synopsys.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Thinh Nguyen authored and Greg Kroah-Hartman committed Dec 24, 2024
1 parent 29ed170 commit a4d7274
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion drivers/usb/gadget/function/f_tcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,17 @@ static void bot_cmd_complete(struct usb_ep *ep, struct usb_request *req)
return;

ret = bot_submit_command(fu, req->buf, req->actual);
if (ret)
if (ret) {
pr_err("%s(%d): %d\n", __func__, __LINE__, ret);
if (!(fu->flags & USBG_BOT_WEDGED))
usb_ep_set_wedge(fu->ep_in);

fu->flags |= USBG_BOT_WEDGED;
bot_enqueue_cmd_cbw(fu);
} else if (fu->flags & USBG_BOT_WEDGED) {
fu->flags &= ~USBG_BOT_WEDGED;
usb_ep_clear_halt(fu->ep_in);
}
}

static int bot_prepare_reqs(struct f_uas *fu)
Expand Down Expand Up @@ -442,6 +451,11 @@ static int usbg_bot_setup(struct usb_function *f,

case US_BULK_RESET_REQUEST:
/* XXX maybe we should remove previous requests for IN + OUT */
if (fu->flags & USBG_BOT_WEDGED) {
fu->flags &= ~USBG_BOT_WEDGED;
usb_ep_clear_halt(fu->ep_in);
}

bot_enqueue_cmd_cbw(fu);
return 0;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/function/tcm.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ struct f_uas {
#define USBG_USE_STREAMS (1 << 2)
#define USBG_IS_BOT (1 << 3)
#define USBG_BOT_CMD_PEND (1 << 4)
#define USBG_BOT_WEDGED (1 << 5)

struct usbg_cdb cmd[USBG_NUM_CMDS];
struct usb_ep *ep_in;
Expand Down

0 comments on commit a4d7274

Please sign in to comment.