Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Sept/Oct 2019 Issue of The NT Insider available

Download PDF here:

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Diagnosing why driver unload fails

RourkeRourke Member Posts: 47

I have a virtual storport miniport. The HwStorFreeAdapterResources frees everything and there are no inverted calls. devcon is used to install/uninstall. But sometimes uninstalling does not unload the driver and a system restart is required. Other times it works. The outcome seems random and unpredictable. Is there a way to diagnose what is causing driver unload to fail?


  • MajorTomMajorTom Member - All Emails Posts: 133
    I would try tracking handles and objects your driver is using.
    Driver Verifier on your driver might catch it.
    Also I would try Code Analysis compilation.
    In case those won’t help there are additional ways but this is as tier 1 triage.
  • RourkeRourke Member Posts: 47

    Of course I always run verifier on very stringent settings; detects nothing. I am also pretty sure the driver frees all resources perfectly and consistently as I described. So what I really need to understand is for what reason Windows decided not to unload it. Right now all I have to go in is sometimes it does, sometimes it doesn't. Are there any log files, events, something to trigger on in the debugger, anything like that? I understand this might be more difficult than a typical driver since storport is the one managing the device objects.

  • Scott_Noone_(OSR)Scott_Noone_(OSR) Administrator Posts: 3,183

    First thing I would do is check C:\windows\inf\ and see if there's anything interesting there.


  • MajorTomMajorTom Member - All Emails Posts: 133
    It seems that your device reference count is not zero. I would try to make memory bp to track ref count and see what increments and does not decrement. Also on the error case you can try use process explorer look for open handles for your device.
  • RourkeRourke Member Posts: 47
    edited October 29

    Here is the output:

    ">>> [Delete Device - ROOT\SCSIADAPTER\0001]
    ">>> Section start 2019/10/29 20:24:20.473
    " cmd: devcon remove root\memex
    "! dvi: Setting needs reboot
    "! dvi: Query-and-Remove failed: 0x13: CR_FAILURE.
    "<<< Section end 2019/10/29 20:24:21.348
    "<<< [Exit status: SUCCESS]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE