Redirected request causes NULL parameter received by the cancel routine

Hi,

I’m working on a WDF driver which is involved in the following steps:

  1. The user mode constantly sends read RequestA down to driver and cancels it after certain timeout. (This is ugly and we’ll change it later but for now we have to stick with it.)
  2. My function driver (not in serial port device stack) receives Read RequestA from user mode and pends it after setting the cancel routine.
  3. Driver formats a pre-created Read RequestB for serial port device stack (IoTarget) and set the completion routine, then sends RequestB to the target.
  4. The serial port holds RequestB until there is something available and completes RequestB.
  5. In RequestB’s completion routine, driver checks the information returned by the serial port driver and does further processing, then returns the extra data to the user mode.

The questions:

  1. It works well in most cases until very rarely that RequestA’s cancel routine is called by framework with NULL parameter. I’m not sure how this happens. I don’t use any synchronization between RequestA’s cancel routine and RequestB’s completion routine as they do not share resources and the data is dedicated to each one. Does anyone know possible reasons that framework could pass a NULL parameter to the cancel routine?

  2. Is there better way (still in kernel) to achieve the same thing other than the above solution? Or any similar samples I can refer to?

Thanks.