Oliver Neukum 7e9b93
From ace17b6ee4f92ab0375d12a1b42494f8590a96b6 Mon Sep 17 00:00:00 2001
Oliver Neukum 7e9b93
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Oliver Neukum 7e9b93
Date: Thu, 21 Apr 2022 19:22:57 -0700
Oliver Neukum 7e9b93
Subject: [PATCH] usb: dwc3: gadget: Only End Transfer for ep0 data phase
Oliver Neukum 7e9b93
Git-commit: ace17b6ee4f92ab0375d12a1b42494f8590a96b6
Oliver Neukum 7e9b93
References: git-fixes
Oliver Neukum 7e9b93
Patch-mainline: v5.19-rc1
Oliver Neukum 7e9b93
Oliver Neukum 7e9b93
The driver shouldn't be able to issue End Transfer to the control
Oliver Neukum 7e9b93
endpoint at anytime. Typically we should only do so in error cases such
Oliver Neukum 7e9b93
as invalid/unexpected direction of Data Phase as described in the
Oliver Neukum 7e9b93
control transfer flow of the programming guide. It _may_ end started
Oliver Neukum 7e9b93
data phase during controller deinitialization from soft disconnect or
Oliver Neukum 7e9b93
driver removal. However, that should not happen because the driver
Oliver Neukum 7e9b93
should be maintained in EP0_SETUP_PHASE during driver tear-down. On
Oliver Neukum 7e9b93
soft-connect, the controller should be reset from a soft-reset and there
Oliver Neukum 7e9b93
should be no issue starting the control endpoint.
Oliver Neukum 7e9b93
Oliver Neukum 7e9b93
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Oliver Neukum 7e9b93
Link: https://lore.kernel.org/r/3c6643678863a26702e4115e9e19d7d94a30d49c.1650593829.git.Thinh.Nguyen@synopsys.com
Oliver Neukum 7e9b93
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Oliver Neukum 7e9b93
Signed-off-by: Oliver Neukum <oneukum@suse.com>
Oliver Neukum 7e9b93
---
Oliver Neukum 7e9b93
 drivers/usb/dwc3/gadget.c | 11 +++++++++++
Oliver Neukum 7e9b93
 1 file changed, 11 insertions(+)
Oliver Neukum 7e9b93
Oliver Neukum 7e9b93
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
Oliver Neukum 7e9b93
index 5e3311e3cc16..4f445f836d32 100644
Oliver Neukum 7e9b93
--- a/drivers/usb/dwc3/gadget.c
Oliver Neukum 7e9b93
+++ b/drivers/usb/dwc3/gadget.c
Oliver Neukum 7e9b93
@@ -3685,6 +3685,17 @@ static void dwc3_reset_gadget(struct dwc3 *dwc)
Oliver Neukum 7e9b93
 void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force,
Oliver Neukum 7e9b93
 	bool interrupt)
Oliver Neukum 7e9b93
 {
Oliver Neukum 7e9b93
+	struct dwc3 *dwc = dep->dwc;
Oliver Neukum 7e9b93
+
Oliver Neukum 7e9b93
+	/*
Oliver Neukum 7e9b93
+	 * Only issue End Transfer command to the control endpoint of a started
Oliver Neukum 7e9b93
+	 * Data Phase. Typically we should only do so in error cases such as
Oliver Neukum 7e9b93
+	 * invalid/unexpected direction as described in the control transfer
Oliver Neukum 7e9b93
+	 * flow of the programming guide.
Oliver Neukum 7e9b93
+	 */
Oliver Neukum 7e9b93
+	if (dep->number <= 1 && dwc->ep0state != EP0_DATA_PHASE)
Oliver Neukum 7e9b93
+		return;
Oliver Neukum 7e9b93
+
Oliver Neukum 7e9b93
 	if (!(dep->flags & DWC3_EP_TRANSFER_STARTED) ||
Oliver Neukum 7e9b93
 	    (dep->flags & DWC3_EP_DELAY_STOP) ||
Oliver Neukum 7e9b93
 	    (dep->flags & DWC3_EP_END_TRANSFER_PENDING))
Oliver Neukum 7e9b93
-- 
Oliver Neukum 7e9b93
2.40.1
Oliver Neukum 7e9b93