This problem is resolved in the Kernel Mode Driver Framework (KMDF) version 1.9 and later. Kernel Mode Driver Framework (KMDF) version 1.9 is available in the Windows 7 version of the Windows Driver Kit (WDK).
A KMDF-based USB device driver developer can work around this problem by performing the following actions:
Register an EvtDeviceReleaseHardware callback routine in the driver's EvtDriverDeviceAdd callback routine.
Allocate a WDFWORKITEM object in the driver's EvtDriverDeviceAdd callback routine.
Allocate and initialize a KEVENT object, queue the work item in the driver's EvtDeviceReleaseHardware callback routine, passing this event as the Context parameter, and wait for the event to be signaled.
In the work item callback routine, delay the thread by approximately 2 seconds and then set the event. The exact delay value required may differ across systems and should be tested prior to final implementation.
The described workaround has two main effects:
It queues a work item which helps delay tearing down the device stack until the work item queue is drained up to this work item (since the USB core stack may complete the USB Selective Suspend Irp through a work item).
It introduces a delay in case the USB core stack’s work item and driver’s work item get executed simultaneously on multi-processor/multi-core systems.
NOTE: This is not a comprehensive solution. It only helps mitigate the problem.