I’m unable to get past the SDV Cleanup4CtlDeviceRegistered rule for my KMDF keyboard driver. Link here: https://docs.microsoft.com/en-us/windows-hardware/drivers/devtest/kmdf-cleanup4ctldeviceregistered
In a nutshell, “If a PnP driver creates a control device object, it must register for the Cleanup callback.”
The details in the SDV error page say this:
“EvtCleanupCallback or EvtDestroyCallback (in WDF_OBJECT_ATTRIBUTES structure for the Control Device)
or EvtDeviceSelfManagedIoCleanup (in WDF_PNPPOWER_EVENT_CALLBACKS structure) must be registered for
the PnP driver that creates the Control Device.”
I have tried all of this individually, and in combination, plus additional things it does not specify. It doesn’t seem to matter. The following is a pared down flow of what happens in AddDevice. I set up both the cleanup callbacks and create the device. Then, if it’s the first device being added, I start the process of creating the control device. SDV fails on the call to WdfControlDeviceInitAllocate(). This seems odd for a couple of reasons.
The detailed description above indicates that you need a SelfManagedIoCleanup callback for the “driver” (seems like a typo, you don’t register that callback on a per-driver basis, you register it on a per-device basis, right?) OR you need to register the Cleanup or Destroy callbacks for the control device. But on that second point, if SDV is throwing the error on my call to WdfControlDeviceInitAllocate(), how does it know what I’m going to do when I create the control device? I haven’t gotten to that WdfDeviceCreate() call yet. And in fact, I registered for Cleanup and Destroy callbacks on that device too just to double check, still errors out. I even register for the cleanup callback on the driver as well . To summarize, every place I call WdfDriverCreate or WdfDeviceCreate I am passing a WDF_OBJECT_ATTIRUBTES with an EvtCleanupCallback set. Still fails.
Has anybody gotten this test to work with a PNP KMDF driver which creates a control device? And if so, any idea what I’m missing? Seems like I must be completely misunderstanding what it says the error is or what the criteria are. Or, there is an SDV bug.
WdfFdoInitSetFilter( DeviceInit);
WDF_PNPPOWER_EVENT_CALLBACKS_INIT( &wdfPnPCallbacks);
wdfPnPCallbacks.EvtDeviceSelfManagedIoCleanup = SelfManagedIoCleanup;
WdfDeviceInitSetPnpPowerEventCallbacks( DeviceInit, &wdfPnPCallbacks);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE( &wdfAttributes, KBDeviceExt);
wdfAttributes.EvtCleanupCallback = ObjectCleanup;
ntStatus = WdfDeviceCreate(
&DeviceInit,
&wdfAttributes,
&hDevice);
if (InterlockedIncrement16(&DeviceCount) == 1)
{
wdfInit = WdfControlDeviceInitAllocate( DriverHandle,
&SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RWX_RES_RWX);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE( &wdfAttributes,
ControlDeviceExt);
wdfAttributes.EvtCleanupCallback = CtrlCleanupCallback;
ntStatus = WdfDeviceCreate( &wdfInit,
&wdfAttributes,
&wdfDevice);
}