Remove lock and asynchronous completion

Hi
I’m using remove locks in my filter driver to make sure it’s safe to detach a device, I need to lend a request and complete it in response to an IOCTL targeted at a named (seperate) device object of my driver. The remove lock is part of my filter device extension so it’s not accesible there, I thought about registering a completion routine (before pending the request) and releasing the lock there, is it the correct approach?

If remove needs to be blocked for the life of the request, then the completion routine is the right answer. That way, you don't "leak" management of one device into another.

If it is KMDF, it is POSSIBLE to attach an extension to the request and tuck a pointer there, but that's the wrong philosophy.