All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] usb: ci_udc: fix interaction with CONFIG_USB_ETH_CDC
@ 2014-06-23 18:02 Stephen Warren
  2014-06-23 19:03 ` Eric Nelson
                   ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Stephen Warren @ 2014-06-23 18:02 UTC (permalink / raw)
  To: u-boot

From: Stephen Warren <swarren@nvidia.com>

ci_udc.c's usb_gadget_unregister_driver() doesn't call driver->unbind()
unlike other USB gadget drivers. Fix it to do this.

Without this, when ether.c's CDC Ethernet device is torn down,
eth_unbind() is never called, so dev->gadget is never set to NULL.
For some reason, usb_eth_halt() is called both at the end of the first
use of the Ethernet device, and prior to any subsequent use. Since
dev->gadget is never cleared, all calls to usb_eth_halt() attempt to
stop, disconnect, and clean up the device, resulting in double cleanup,
which hangs U-Boot on my Tegra device at least.

ci_udc allocates its own singleton EP0 request object, and cleans it up
during usb_gadget_unregister_driver(). This appears necessary when using
the USB gadget framework in U-Boot, since that does not allocate/free
the EP0 request. However, the CDC Ethernet driver *does* allocate and
free its own EP0 requests. Consequently, we must protect
ci_ep_free_request() against double-freeing the request.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
---
 drivers/usb/gadget/ci_udc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index b18bee43ad89..c3f6467b7db4 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -226,8 +226,11 @@ static void ci_ep_free_request(struct usb_ep *ep, struct usb_request *req)
 	int num;
 
 	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
-	if (num == 0)
+	if (num == 0) {
+		if (!controller.ep0_req)
+			return;
 		controller.ep0_req = 0;
+	}
 
 	if (ci_req->b_buf)
 		free(ci_req->b_buf);
@@ -909,6 +912,9 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
 {
 	udc_disconnect();
 
+	driver->unbind(&controller.gadget);
+	controller.driver = NULL;
+
 	ci_ep_free_request(&controller.ep[0].ep, &controller.ep0_req->req);
 	free(controller.items_mem);
 	free(controller.epts);
-- 
1.8.1.5

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

end of thread, other threads:[~2014-06-30 23:56 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23 18:02 [U-Boot] [PATCH] usb: ci_udc: fix interaction with CONFIG_USB_ETH_CDC Stephen Warren
2014-06-23 19:03 ` Eric Nelson
2014-06-25 13:51 ` Marek Vasut
2014-06-25 16:06   ` Stephen Warren
2014-06-27 21:37     ` Jörg Krause
2014-06-27 21:52       ` Jörg Krause
2014-06-27 21:56         ` Stephen Warren
2014-06-27 23:27           ` Jörg Krause
2014-06-27 21:55       ` Stephen Warren
2014-06-27 23:16         ` Jörg Krause
2014-06-27 23:37           ` Stephen Warren
2014-06-28  0:09             ` Jörg Krause
2014-06-28  1:34             ` Jörg Krause
2014-06-28 20:37               ` Jörg Krause
2014-06-28 20:45                 ` Marek Vasut
2014-06-28 20:53                   ` Jörg Krause
2014-06-29 20:33                     ` Jörg Krause
2014-06-30  9:37                       ` Marek Vasut
2014-06-30 13:34                         ` Jörg Krause
2014-06-30 16:02               ` Stephen Warren
2014-06-30 19:55                 ` Stephen Warren
2014-06-30 22:44                   ` Jörg Krause
2014-06-30 22:51                     ` Stephen Warren
2014-06-30 23:17                       ` Jörg Krause
2014-06-30 23:56                         ` Marek Vasut
2014-06-30 20:55                 ` Jörg Krause
2014-06-30 21:15                   ` Marek Vasut
2014-06-30 21:43                     ` Jörg Krause
2014-06-30 21:50                       ` Marek Vasut
2014-06-25 20:20 ` Marek Vasut

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.