From cf2527269fc6f45f685f6597b0246e77c68ce7d1 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Fri, 28 May 2021 12:48:04 +0200 Subject: [PATCH] qemu-usb: allocate host devices after webcam Because qemu-usb allocated host devices after 'USB_HOST_DEVICE' in the object array and 'USB_WEBCAM' is loacated after 'USB_HOST_DEVICE' the webcam model can overwrite an already allocated pass-through device. As a solution add the 'USB_FIRST_FREE' to make it clear from where host devices can be allocated. Also increase the number of supported host devices to eight. fixes #4182 --- repos/libports/src/lib/qemu-usb/qemu_emul.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/repos/libports/src/lib/qemu-usb/qemu_emul.cc b/repos/libports/src/lib/qemu-usb/qemu_emul.cc index f0330086f3..21538e788b 100644 --- a/repos/libports/src/lib/qemu-usb/qemu_emul.cc +++ b/repos/libports/src/lib/qemu-usb/qemu_emul.cc @@ -277,8 +277,9 @@ struct Object_pool USB_BUS, /* bus driver */ USB_DEVICE, /* USB device driver */ USB_HOST_DEVICE, /* USB host device driver */ - USB_WEBCAM, /* USB host device driver */ - MAX = 10 /* host devices (USB_HOST_DEVICE - MAX) */ + USB_WEBCAM, /* USB webcam device driver */ + USB_FIRST_FREE, /* first free device */ + MAX = 14 /* host devices (USB_FIRST_FREE to MAX) */ }; bool used[MAX]; @@ -286,7 +287,7 @@ struct Object_pool Wrapper *create_object() { - for (unsigned i = USB_HOST_DEVICE + 1; i < MAX; i++) { + for (unsigned i = USB_FIRST_FREE; i < MAX; i++) { if (used[i] == false) { used[i] = true; return &obj[i]; @@ -297,7 +298,7 @@ struct Object_pool void free_object(Wrapper *w) { - for (unsigned i = USB_HOST_DEVICE + 1; i < MAX; i++) + for (unsigned i = USB_FIRST_FREE; i < MAX; i++) if (w == &obj[i]) { used[i] = false; break;