public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/4] usb: ci_udc: detect queued requests on ep0
@ 2014-05-29 20:53 Stephen Warren
  2014-05-29 20:53 ` [U-Boot] [PATCH 2/4] usb: ci_udc: use a single descriptor for ep0 Stephen Warren
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Stephen Warren @ 2014-05-29 20:53 UTC (permalink / raw)
  To: u-boot

From: Stephen Warren <swarren@nvidia.com>

The flipping of ep0 between IN and OUT relies on ci_ep_queue() consuming
the current IN/OUT setting immediately. If this is deferred to a later
point when the req is pulled out of ci_req->queue, then the IN/OUT
setting may have been changed since the req was queued, and state will
get out of sync. This condition doesn't occur today, but could if bugs
were introduced later, and this error-check will save a lot of debugging
time.

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

diff --git a/drivers/usb/gadget/ci_udc.c b/drivers/usb/gadget/ci_udc.c
index 9cd003636a44..a68a85f84e70 100644
--- a/drivers/usb/gadget/ci_udc.c
+++ b/drivers/usb/gadget/ci_udc.c
@@ -397,6 +397,21 @@ static int ci_ep_queue(struct usb_ep *ep,
 	num = ci_ep->desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
 	in = (ci_ep->desc->bEndpointAddress & USB_DIR_IN) != 0;
 
+	if (!num && ci_ep->req_primed) {
+		/*
+		 * The flipping of ep0 between IN and OUT relies on
+		 * ci_ep_queue consuming the current IN/OUT setting
+		 * immediately. If this is deferred to a later point when the
+		 * req is pulled out of ci_req->queue, then the IN/OUT setting
+		 * may have been changed since the req was queued, and state
+		 * will get out of sync. This condition doesn't occur today,
+		 * but could if bugs were introduced later, and this error
+		 * check will save a lot of debugging time.
+		 */
+		printf("%s: ep0 transaction already in progress\n", __func__);
+		return -EPROTO;
+	}
+
 	ret = ci_bounce(ci_req, in);
 	if (ret)
 		return ret;
-- 
1.8.1.5

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

end of thread, other threads:[~2014-06-10 18:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-29 20:53 [U-Boot] [PATCH 1/4] usb: ci_udc: detect queued requests on ep0 Stephen Warren
2014-05-29 20:53 ` [U-Boot] [PATCH 2/4] usb: ci_udc: use a single descriptor for ep0 Stephen Warren
2014-05-29 20:53 ` [U-Boot] [PATCH 3/4] usb: ci_udc: pre-allocate ep0 req Stephen Warren
2014-05-29 20:53 ` [U-Boot] [PATCH 4/4] usb: ci_udc: complete ep0 direction handling Stephen Warren
2014-06-01 17:22   ` Marek Vasut
2014-06-10 15:58     ` Stephen Warren
2014-06-10 18:49       ` Marek Vasut

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