Linux USB
 help / color / mirror / Atom feed
* [RFC PATCH] usb: udc: run disconnect callback before pull up zero
@ 2024-01-19  5:48 yuan linyu
  2024-01-19 14:49 ` Alan Stern
  0 siblings, 1 reply; 7+ messages in thread
From: yuan linyu @ 2024-01-19  5:48 UTC (permalink / raw)
  To: Alan Stern, Greg Kroah-Hartman; +Cc: linux-usb, yuan linyu

When write UDC to empty and unbind gadget driver from gadget device, it is
possible that there are many queue failures for mass storage function.

The root cause is on platform like dwc3, if pull down called first, the
queue operation from mass storage main thread will fail as it is belong to
another thread context and always try to receive a command from host.

In order to fix it, call gadget driver disconnect callback first, mass
storage function driver will disable endpoints and clear running flag,
so there will be no request queue to UDC.

One note is when call disconnect callback first, it mean function will
disable endpoints before stop UDC controller.

Signed-off-by: yuan linyu <yuanlinyu@hihonor.com>
---
 drivers/usb/gadget/udc/core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index d59f94464b87..9c48cec89e35 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -774,15 +774,15 @@ static int usb_gadget_disconnect_locked(struct usb_gadget *gadget)
 		goto out;
 	}
 
-	ret = gadget->ops->pullup(gadget, 0);
-	if (!ret)
-		gadget->connected = 0;
-
 	mutex_lock(&udc_lock);
 	if (gadget->udc->driver)
 		gadget->udc->driver->disconnect(gadget);
 	mutex_unlock(&udc_lock);
 
+	ret = gadget->ops->pullup(gadget, 0);
+	if (!ret)
+		gadget->connected = 0;
+
 out:
 	trace_usb_gadget_disconnect(gadget, ret);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-01-22  2:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-19  5:48 [RFC PATCH] usb: udc: run disconnect callback before pull up zero yuan linyu
2024-01-19 14:49 ` Alan Stern
2024-01-20  1:12   ` Thinh Nguyen
2024-01-20 15:00     ` Alan Stern
2024-01-22  1:32       ` yuanlinyu 00030184
2024-01-22  2:30         ` Alan Stern
2024-01-22  2:54           ` yuanlinyu 00030184

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox