Under the model KMDF for a USB device, I’ve just discovered the hard way
that each call to WdfUsbInterfaceGetConfiguredPipe must be checked for
success, otherwise a kernel bugcheck is possible - generally associated with
unplugging an active device. I confess that I borrowed the following code
fragment from the Win DDK USBSamp and did not perform a mental PREFast and
documentation validation:
pipe = WdfUsbInterfaceGetConfiguredPipe(pDevContext->UsbInterface,
i, //PipeIndex,
NULL
);
UsbSamp_DbgPrint(3, (“Aborting open pipe %d\n”, i));
status = WdfUsbTargetPipeAbortSynchronously(pipe,
WDF_NO_HANDLE, // WDFREQUEST
NULL);//PWDF_REQUEST_SEND_OPTIONS
That’s right: there is no check that the pipe is valid (not NULL) before
passing it to WdfUsbTargetPipeAbortSynchronously(). And the documentation
states that it will bugcheck if the passed handle is invalid. PREFast and
SDV don’t call this out.