linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jerry Zhang <zhangjerry@google.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Cc: Michal Nazarewicz <mina86@mina86.com>,
	Krzysztof Opasiak <kopasiak90@gmail.com>,
	Badhri Jagan Sridharan <badhri@google.com>,
	Andrzej Pietrasiewicz <andrzej.p@samsung.com>,
	Lars-Peter Clausen <lars@metafoo.de>,
	felixhaedicke@web.de, Jerry Zhang <zhangjerry@google.com>
Subject: [1/3] usb: gadget: f_fs: Only return delayed status when len is 0
Date: Mon, 16 Apr 2018 18:17:40 -0700	[thread overview]
Message-ID: <20180417011742.192184-2-zhangjerry@google.com> (raw)

Commit 1b9ba000 ("Allow function drivers to pause control
transfers") states that USB_GADGET_DELAYED_STATUS is only
supported if data phase is 0 bytes.

It seems that when the length is not 0 bytes, there is no
need to explicitly delay the data stage since the transfer
is not completed until the user responds. However, when the
length is 0, there is no data stage and the transfer is
finished once setup() returns, hence there is a need to
explicitly delay completion.

This manifests as the following bugs:

Prior to 946ef68ad4e4 ('Let setup() return
USB_GADGET_DELAYED_STATUS'), when setup is 0 bytes, ffs
would require user to queue a 0 byte request in order to
clear setup state. However, that 0 byte request was actually
not needed and would hang and cause errors in other setup
requests.

After the above commit, 0 byte setups work since the gadget
now accepts empty queues to ep0 to clear the delay, but all
other setups hang.

Fixes: 946ef68ad4e4 ("Let setup() return USB_GADGET_DELAYED_STATUS")
Signed-off-by: Jerry Zhang <zhangjerry@google.com>
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index 7d5b1c448eb2..4b2cb9d93176 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3271,7 +3271,7 @@ static int ffs_func_setup(struct usb_function *f,
 	__ffs_event_add(ffs, FUNCTIONFS_SETUP);
 	spin_unlock_irqrestore(&ffs->ev.waitq.lock, flags);
 
-	return USB_GADGET_DELAYED_STATUS;
+	return creq->wLength == 0 ? USB_GADGET_DELAYED_STATUS : 0;
 }
 
 static bool ffs_func_req_match(struct usb_function *f,

             reply	other threads:[~2018-04-17  1:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-17  1:17 Jerry Zhang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-06-04 19:44 [1/3] usb: gadget: f_fs: Only return delayed status when len is 0 Jerry Zhang
2018-07-26 10:45 Felipe Balbi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180417011742.192184-2-zhangjerry@google.com \
    --to=zhangjerry@google.com \
    --cc=andrzej.p@samsung.com \
    --cc=badhri@google.com \
    --cc=balbi@kernel.org \
    --cc=felixhaedicke@web.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=kopasiak90@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=mina86@mina86.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).