diff mbox series

hw/usb/core: fix inconsistent ep and pid (UBS_TOKEN_SETUP)

Message ID 20230129105406.2548988-1-cyruscyliu@gmail.com (mailing list archive)
State New, archived
Headers show
Series hw/usb/core: fix inconsistent ep and pid (UBS_TOKEN_SETUP) | expand

Commit Message

Qiang Liu Jan. 29, 2023, 10:54 a.m. UTC
Sometimes, `ep` is not enforced to 0 when `pid` is `USB_TOKEN_SETUP`. I
trigger this through dwc2
(https://lists.gnu.org/archive/html/qemu-devel/2021-06/msg07179.html).
A similar bug was found
[here](https://gitlab.com/qemu-project/qemu/-/issues/119) and
[here](https://gitlab.com/qemu-project/qemu/-/issues/303).

Fixes: 25d5de7d81a5 ("usb: link packets to endpoints not devices")
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/119
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/303
Cc: Paul Zimmerman <pauldzim@gmail.com>
Signed-off-by: Qiang Liu <cyruscyliu@gmail.com>
---
 hw/usb/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/hw/usb/core.c b/hw/usb/core.c
index 975f76250a..eb50a7bff8 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -738,7 +738,7 @@  struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep)
     struct USBEndpoint *eps;
 
     assert(dev != NULL);
-    if (ep == 0) {
+    if (ep == 0 || pid == USB_TOKEN_SETUP) {
         return &dev->ep_ctl;
     }
     assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT);