Returning Error From Add Device

Hi All,

I am writing a function driver and was wondering what will happen if the addDevice callback returns an error. For example lets say a addDevice is doing the following:-

  1. Register power management callbacks
  2. Register FDO’s cleanup and destroy callbacks.
  3. calls WdfDeviceCreate
  4. calls WdfDeviceCreateDeviceInterface
  5. create a Manual Dispatch queue

Now lets say while creating queues, the driver fails (for whatever reason) and I return the error status to the above layer. Will the framework delete the device object and cleanup the device interface or when I detect a error in step-5 I will have to perform the cleanup?

Regards

  • Aj

When you return an error from AddDevice as the FDO, the stack will be torn down. KMDF will delete the WDFDEVICE on the driver’s behalf and all objects and state associated with the WDFDEVICE are cleaned up as part of processing the delete. In your example, the internal bookkeeping for the device interface will be freed and the manual WDFQUEUE will be disposed and deleted (so that the underlying object tree is cleaned up properly and all driver assigned cleanup() and destroy() callbacks are called).