Ticket #18008: usb_hid_device_remove_fix.patch

File usb_hid_device_remove_fix.patch, 1.3 KB (added by zelenoviy, 2 years ago)

fix patch

  • src/add-ons/kernel/drivers/input/usb_hid/Driver.cpp

    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..9dbed21dac 100644
    a b usb_hid_device_removed(void *cookie)  
    192192    int32 parentCookie = (int32)(addr_t)cookie;
    193193    TRACE("device_removed(%" B_PRId32 ")\n", parentCookie);
    194194
     195    // removed device may contains multiple hid devices on multiple interfaces
     196    // we must go through all published devices and remove all that belong to this parent
    195197    for (int32 i = 0; i < gDeviceList->CountDevices(); i++) {
    196198        ProtocolHandler *handler = (ProtocolHandler *)gDeviceList->DeviceAt(i);
    197199        if (!handler)
    usb_hid_device_removed(void *cookie)  
    202204            continue;
    203205
    204206        // remove all the handlers
    205         for (uint32 i = 0;; i++) {
    206             handler = device->ProtocolHandlerAt(i);
     207        for (uint32 j = 0;; j++) {
     208            handler = device->ProtocolHandlerAt(j);
    207209            if (handler == NULL)
    208210                break;
    209211
    210212            gDeviceList->RemoveDevice(NULL, handler);
     213            i--; // device count changed, adjust index
    211214        }
    212215
    213216        // this handler's device belongs to the one removed
    usb_hid_device_removed(void *cookie)  
    216219            device->Removed();
    217220        } else
    218221            delete device;
    219 
    220         break;
    221222    }
    222223
    223224    mutex_unlock(&sDriverLock);