Hi,
I have developed USB device driver based on the Chris Cant’s book
“Writing windows WDM Device Drivers”.
In the dispatch routines, the book uses LockDevice() function to prevent
from stopping a device during dispatch process.
After process dispatch routine, UnlockDevice() is called.
In the StopDevice handler, usally the function waits StoppingEvent that sets in the LockDevice.
I think this scheme is usally used, not to specific to this book.
My question :
I think that in the case of fail to power up, before return CompleteIrp(), UnlockDevice()
should be called. Is this right?
============= original code =====================
NTSTATUS Wdm2Read( IN PDEVICE_OBJECT fdo, IN PIRP Irp)
{
NTSTATUS status = PowerUpDevice(fdo);
if( !NT_SUCCESS(status))
return CompleteIrp(Irp, status, 0);
…
UnlockDevice(dx);
}
===============================================
============= modified code =====================
NTSTATUS Wdm2Read( IN PDEVICE_OBJECT fdo, IN PIRP Irp)
{
NTSTATUS status = PowerUpDevice(fdo);
if( !NT_SUCCESS(status)) {
UnlockDevice(dx);
return CompleteIrp(Irp, status, 0);
}
…
UnlockDevice(dx);
}
Best regards,
HyungJune Kim