Prevent PDO from becoming a phantom device after parent is removed

Disclaimer: This is for a hobby project, this isnt for work ?. I am a beginner when it comes to driver development.

I have a kmdf wdf driver that is root enumerated and behaves kind of like a bus or fdo. It creates a pdo when it gets installed via devcon for now.
After it is installed it creates a pdo. This works. But when I remove my driver the pdo does not get removed properly but keeps its registry entries and therefore becomes a non-present aka a phantom device. Since this phantom device allocates a com number this is really annoying since I always have to remove it manually. Is there a way to force the removal of a pdo? I already tried both static enumeration with wdfpdomarkmissing on EvtDeviceReleaseHardware and dynamic enumeration using WdfChildListRequestChildEject. Both of them are not working.

One thing you could do is install your driver with a proper installer. During uninstall make a custom action that calls DIF_REMOVE for each of your devices you want to forcefully remove.

How do you create your PDO? You said you’re using KMDF. If you’re using the provided WdfChildList APIs, then it is your responsibility at unplug time to call WdfChidListBeginScan/WdfChlidListEndScan, which tells the system “I have no child PDOs”.

Yeah that is exactly what I am doing. If for example I do this during an ioctl request, the pdo get’s “unplugged” too. But it just gets grayed out (becomes a phantom device). I want it removed from the registry completely.