KMDF Error recovery after device creation

I am a bit lost on how to recover from an error after the device has been created in, e.g., EvtDriverDeviceAdd. After the device object has been created, I have other tasks to do, like add interfaces and queues. If these tasks do not complete successfully:
A) I can’t return the error code, since the framework will ignore it. (Since the device object has been created, it silently changes my error code to STATUS_SUCCESS).
B) I can’t delete the device object. (Not allowed by the framework).
C) So, my current code will bring down the system.

But this just seems extreme. Is there a better way to do this?

-Steve

  1. the framework only “ignores” the error code returned from
    EvtDriverDeviceAdd if you are a filter driver. This is inherited from
    WDM. If you fail DeviceAdd, the stack will still get started and run
    without your filter and the framework will gracefully cleanup your
    device object and everything you created. If you are the function
    driver, KMDF certainly does *NOT* ignore the error code. Again, you
    will get graceful cleanup of your device and its objects, but the stack
    will not get started. If you want the filter to be able to fail the
    starting of the stack in you have an error in DeviceAdd, register for
    EvtDevicePrepareHardware and return !NT_SUCCESS from there.

b) correct, KMDF will automatically delete the device for you in either
(filter or function) driver at the right time

c) why does it bring down the system? What stack are you in? is it
b/c you are dereferencing invalid memory?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@hotmail.com
Sent: Thursday, June 07, 2007 6:31 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] KMDF Error recovery after device creation

I am a bit lost on how to recover from an error after the device has
been created in, e.g., EvtDriverDeviceAdd. After the device object has
been created, I have other tasks to do, like add interfaces and queues.
If these tasks do not complete successfully:
A) I can’t return the error code, since the framework will ignore it.
(Since the device object has been created, it silently changes my error
code to STATUS_SUCCESS).
B) I can’t delete the device object. (Not allowed by the framework).
C) So, my current code will bring down the system.

But this just seems extreme. Is there a better way to do this?

-Steve


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Doron -

Thanks! I was reading the docs a bit fast, I guess, and I was thinking the framework would ignore the error for function drivers too. Regarding (c), I meant that my error-checking code would bugcheck because I thought I couldn’t return an error from that callback. But since I can return an error, that’s just what I’ll do.

-Steve