From afe965f464ff4c77527f5b6a4990f0bfaae2d202 Mon Sep 17 00:00:00 2001 From: Zelenoviy Date: Tue, 1 Nov 2022 03:58:25 +0700 Subject: [PATCH] usb_hid: properly device remove handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small fix to device remove handling, when multiple hid-devices published on multiple interfaces. Fixes #18008. Change-Id: I64e1a9fb6cbac503e3d55b51ee0539bb6f1908e4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5773 Tested-by: Commit checker robot Reviewed-by: Jérôme Duval --- src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp b/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp index a1435c457c..deccd43550 100644 --- a/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp +++ b/src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp @@ -192,6 +192,8 @@ usb_hid_device_removed(void *cookie) int32 parentCookie = (int32)(addr_t)cookie; TRACE("device_removed(%" B_PRId32 ")\n", parentCookie); + // removed device may contain multiple HID devices on multiple interfaces + // we must go through all published devices and remove all that belong to this parent for (int32 i = 0; i < gDeviceList->CountDevices(); i++) { ProtocolHandler *handler = (ProtocolHandler *)gDeviceList->DeviceAt(i); if (!handler) @@ -202,12 +204,13 @@ usb_hid_device_removed(void *cookie) continue; // remove all the handlers - for (uint32 i = 0;; i++) { - handler = device->ProtocolHandlerAt(i); + for (uint32 j = 0;; j++) { + handler = device->ProtocolHandlerAt(j); if (handler == NULL) break; gDeviceList->RemoveDevice(NULL, handler); + i--; // device count changed, adjust index } // this handler's device belongs to the one removed @@ -216,8 +219,6 @@ usb_hid_device_removed(void *cookie) device->Removed(); } else delete device; - - break; } mutex_unlock(&sDriverLock);