All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/usb/hcd-dwc2: Enforce epnum to 0 for the control endpoint to avoid the assertion failure in usb_ep_get()
@ 2021-06-27  3:28 Qiang Liu
  2021-06-27  5:21 ` Qiang Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Qiang Liu @ 2021-06-27  3:28 UTC (permalink / raw)
  Cc: open list:All patches CC here, Qiang Liu, Gerd Hoffmann, Paul Zimmerman

When eptype is USB_ENDPOINT_XFER_CONTROL and pid is
TSIZ_SC_MC_PID_SETUP, usb_ep_get() should return the control endpoint.
In hw/usb/core.c, the assumed epnum of the control endpoint is 0. When
epnum is not 0, usb_ep_get() will crash due to the check assert(pid ==
USB_TOKEN_IN || pid == USB_TOKEN_OUT).

The description
http://www.capital-micro.com/PDF/CME-M7_Family_User_Guide_EN.pdf
(18.5.3.4 (14), 18.5.3.4 (10)) a) mentions that the pid is maintained by
the host, b) but doesn't mention that whether the epnum should be 0 for
the control endpoint. However, usb_ep_get() assumes it is 0. To avoid
potential assertion failure in usb_ep_get(), we could enforce epnum to 0
and warn users.

Fixes: 153ef1662c3 ("dwc-hsotg (dwc2) USB host controller emulation")
Signed-off-by: Qiang Liu <cyruscyliu@gmail.com>
---
 hw/usb/hcd-dwc2.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c
index e1d96ac..65d9d46 100644
--- a/hw/usb/hcd-dwc2.c
+++ b/hw/usb/hcd-dwc2.c
@@ -636,6 +636,11 @@ static void dwc2_enable_chan(DWC2State *s,  uint32_t index)
     }
 
     if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) {
+        if (epnum != 0) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "epnum should be 0 for the control endpoint\n");
+            epnum = 0;
+        }
         pid = USB_TOKEN_SETUP;
     } else {
         pid = epdir ? USB_TOKEN_IN : USB_TOKEN_OUT;
-- 
2.7.4



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

end of thread, other threads:[~2021-07-21 11:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27  3:28 [PATCH] hw/usb/hcd-dwc2: Enforce epnum to 0 for the control endpoint to avoid the assertion failure in usb_ep_get() Qiang Liu
2021-06-27  5:21 ` Qiang Liu
2021-07-04 22:27   ` Paul Zimmerman
2021-07-05  1:34     ` Qiang Liu
2021-07-21 11:44       ` Gerd Hoffmann

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.