aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2020-05-29 09:22:24 +0200
committerGerd Hoffmann <kraxel@redhat.com>2020-06-17 09:12:33 +0200
commit54cdfe511219b8051046be55a6e156c4f08ff7ff (patch)
tree7254f061e62bcac179c2ea564042a0bb78a3533a
parent9f815e83e983d247a3cd67579d2d9c1765adc644 (diff)
usb-host: workaround libusb bug
libusb seems to no allways call the completion callback for requests canceled (which it is supposed to do according to the docs). So add a limit to avoid qemu waiting forever. Tested-by: BALATON Zoltan <balaton@eik.bme.hu> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Message-Id: <20200529072225.3195-1-kraxel@redhat.com>
-rw-r--r--hw/usb/host-libusb.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index e88db544bc..ad7ed8fb0c 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -972,6 +972,7 @@ fail:
static void usb_host_abort_xfers(USBHostDevice *s)
{
USBHostRequest *r, *rtmp;
+ int limit = 100;
QTAILQ_FOREACH_SAFE(r, &s->requests, next, rtmp) {
usb_host_req_abort(r);
@@ -982,6 +983,19 @@ static void usb_host_abort_xfers(USBHostDevice *s)
memset(&tv, 0, sizeof(tv));
tv.tv_usec = 2500;
libusb_handle_events_timeout(ctx, &tv);
+ if (--limit == 0) {
+ /*
+ * Don't wait forever for libusb calling the complete
+ * callback (which will unlink and free the request).
+ *
+ * Leaking memory here, to make sure libusb will not
+ * access memory which we have released already.
+ */
+ QTAILQ_FOREACH_SAFE(r, &s->requests, next, rtmp) {
+ QTAILQ_REMOVE(&s->requests, r, next);
+ }
+ return;
+ }
}
}