Skip to content

Commit 2fe5a9a

Browse files
Merge pull request #16 from FrameworkComputer/fix-disabling
Fix device cleanup to run on device disable
2 parents 7301780 + 2bb7505 commit 2fe5a9a

3 files changed

Lines changed: 43 additions & 10 deletions

File tree

FrameworkArgb/Device.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ Return Value:
319319
WdfFdoInitSetFilter(DeviceInit);
320320

321321
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT);
322+
deviceAttributes.EvtCleanupCallback = FrameworkArgbEvtDeviceCleanup;
322323

323324
status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device);
324325

@@ -740,3 +741,39 @@ Return Value:
740741

741742
return status;
742743
}
744+
745+
VOID
746+
FrameworkArgbEvtDeviceCleanup(
747+
_In_ WDFOBJECT DeviceObject
748+
)
749+
/*++
750+
Routine Description:
751+
752+
Free all the resources allocated for the device.
753+
Called when the device is removed or disabled.
754+
755+
Arguments:
756+
757+
DeviceObject - handle to a WDF Device object.
758+
759+
Return Value:
760+
761+
VOID.
762+
763+
--*/
764+
{
765+
PDEVICE_CONTEXT DeviceContext;
766+
767+
TraceInformation("%!FUNC! Entry");
768+
769+
DeviceContext = GetDeviceContext(DeviceObject);
770+
771+
// Close handle to EC driver
772+
if (DeviceContext && DeviceContext->CrosEcHandle && DeviceContext->CrosEcHandle != INVALID_HANDLE_VALUE) {
773+
CloseHandle(DeviceContext->CrosEcHandle);
774+
DeviceContext->CrosEcHandle = INVALID_HANDLE_VALUE;
775+
TraceInformation("%!FUNC! Closed CrosEc Handle");
776+
}
777+
778+
TraceInformation("%!FUNC! Exit");
779+
}

FrameworkArgb/Device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ typedef UCHAR HID_REPORT_DESCRIPTOR, * PHID_REPORT_DESCRIPTOR;
3232
DRIVER_INITIALIZE DriverEntry;
3333
EVT_WDF_DRIVER_DEVICE_ADD EvtDeviceAdd;
3434
EVT_WDF_TIMER EvtTimerFunc;
35+
EVT_WDF_OBJECT_CONTEXT_CLEANUP FrameworkArgbEvtDeviceCleanup;
3536

3637
#define MAX_LAMPARRAY_LAMP_COUNT 256
3738
//#define LAMPARRAY_WIDTH 80000 // 80mm

FrameworkArgb/Driver.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ FrameworkArgbEvtDriverContextCleanup(
150150
Routine Description:
151151
152152
Free all the resources allocated in DriverEntry.
153+
Note: Device-specific cleanup (like EC handle) is done in
154+
FrameworkArgbEvtDeviceCleanup, not here.
153155
154156
Arguments:
155157
@@ -161,19 +163,10 @@ Return Value:
161163
162164
--*/
163165
{
164-
PDEVICE_CONTEXT DeviceContext;
166+
UNREFERENCED_PARAMETER(DriverObject);
165167

166168
TraceInformation("%!FUNC! Entry");
167169

168-
DeviceContext = GetDeviceContext(DriverObject);
169-
// Close handle to EC driver
170-
if (DeviceContext && DeviceContext->CrosEcHandle && DeviceContext->CrosEcHandle != INVALID_HANDLE_VALUE) {
171-
CloseHandle(DeviceContext->CrosEcHandle);
172-
DeviceContext->CrosEcHandle = INVALID_HANDLE_VALUE;
173-
TraceError("%!FUNC! Failed to close CrosEc Handle");
174-
}
175-
TraceInformation("%!FUNC! Closed CrosEc Handle");
176-
177170
//
178171
// Stop WPP Tracing
179172
//
@@ -182,4 +175,6 @@ Return Value:
182175
#else
183176
WPP_CLEANUP(WdfDriverWdmGetDriverObject((WDFDRIVER)DriverObject));
184177
#endif
178+
179+
TraceInformation("%!FUNC! Exit");
185180
}

0 commit comments

Comments
 (0)