All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Cc: John Youn <John.Youn@synopsys.com>,
	Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Wesley Cheng <quic_wcheng@quicinc.com>
Subject: [PATCH 5/6] usb: dwc3: gadget: Only End Transfer for ep0 data phase
Date: Thu, 21 Apr 2022 19:22:57 -0700	[thread overview]
Message-ID: <3c6643678863a26702e4115e9e19d7d94a30d49c.1650593829.git.Thinh.Nguyen@synopsys.com> (raw)
In-Reply-To: <cover.1650593829.git.Thinh.Nguyen@synopsys.com>

The driver shouldn't be able to issue End Transfer to the control
endpoint at anytime. Typically we should only do so in error cases such
as invalid/unexpected direction of Data Phase as described in the
control transfer flow of the programming guide. It _may_ end started
data phase during controller deinitialization from soft disconnect or
driver removal. However, that should not happen because the driver
should be maintained in EP0_SETUP_PHASE during driver tear-down. On
soft-connect, the controller should be reset from a soft-reset and there
should be no issue starting the control endpoint.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
 drivers/usb/dwc3/gadget.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index e5f07c0e8ad9..7c4d5f671687 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3641,6 +3641,17 @@ static void dwc3_reset_gadget(struct dwc3 *dwc)
 void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force,
 	bool interrupt)
 {
+	struct dwc3 *dwc = dep->dwc;
+
+	/*
+	 * Only issue End Transfer command to the control endpoint of a started
+	 * Data Phase. Typically we should only do so in error cases such as
+	 * invalid/unexpected direction as described in the control transfer
+	 * flow of the programming guide.
+	 */
+	if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE)
+		return;
+
 	if (!(dep->flags & DWC3_EP_TRANSFER_STARTED) ||
 	    (dep->flags & DWC3_EP_DELAY_STOP) ||
 	    (dep->flags & DWC3_EP_END_TRANSFER_PENDING))
-- 
2.28.0


  parent reply	other threads:[~2022-04-22  2:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-22  2:22 [PATCH 0/6] usb: dwc3: gadget: Rework pullup Thinh Nguyen
2022-04-22  2:22 ` [PATCH 1/6] usb: dwc3: gadget: Prevent repeat pullup() Thinh Nguyen
2022-04-22  2:22 ` [PATCH 2/6] usb: dwc3: gadget: Refactor pullup() Thinh Nguyen
2022-04-22  2:22 ` [PATCH 3/6] usb: dwc3: gadget: Don't modify GEVNTCOUNT in pullup() Thinh Nguyen
2022-04-22  2:22 ` [PATCH 4/6] usb: dwc3: ep0: Don't prepare beyond Setup stage Thinh Nguyen
2022-05-03 11:01   ` Pavan Kondeti
2022-05-23 23:22     ` Thinh Nguyen
2022-05-23 23:33       ` Wesley Cheng
2022-05-24  0:25         ` Thinh Nguyen
2022-04-22  2:22 ` Thinh Nguyen [this message]
2022-04-22  2:23 ` [PATCH 6/6] usb: dwc3: gadget: Delay issuing End Transfer Thinh Nguyen
2022-04-28  0:59   ` Wesley Cheng
2022-04-28  1:31     ` Thinh Nguyen
2022-05-03 11:12   ` Pavan Kondeti
2022-05-23 23:23     ` Thinh Nguyen
2022-04-26 21:05 ` [PATCH 0/6] usb: dwc3: gadget: Rework pullup Wesley Cheng
2022-05-20  1:02   ` Wesley Cheng
2022-05-24  0:30     ` Thinh Nguyen
2022-05-24  1:34       ` Wesley Cheng
2022-05-25 17:50         ` Wesley Cheng
2022-05-26  0:25           ` Thinh Nguyen
2022-06-01 21:18             ` Wesley Cheng
2022-06-01 22:07               ` Thinh Nguyen

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=3c6643678863a26702e4115e9e19d7d94a30d49c.1650593829.git.Thinh.Nguyen@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_wcheng@quicinc.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.