From e3f18be89e3d3336ce3c1c3fbf492a02caca6892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Thu, 2 Jul 2026 23:37:40 +0200 Subject: [PATCH] Example correction --- src/Dmf_BusFilter.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Dmf_BusFilter.md b/src/Dmf_BusFilter.md index 705d894..c3b988e 100644 --- a/src/Dmf_BusFilter.md +++ b/src/Dmf_BusFilter.md @@ -431,7 +431,7 @@ Any WDF context-allocation failure | Returned from `WdfObjectAllocateContext`. Parameter | Description ----|---- -BusFilterConfig | Pointer to a fully populated `DMF_BusFilter_CONFIG`. Initialize with `DMF_BusFilter_CONFIG_INIT` before setting callbacks. The caller retains ownership; the library copies the config internally. +BusFilterConfig | Pointer to a fully populated `DMF_BusFilter_CONFIG`. Initialize with `DMF_BusFilter_CONFIG_INIT` before setting callbacks. The library copies the struct internally; the pointer does not need to remain valid after `DMF_BusFilter_Initialize` returns, so a stack-local variable in `DriverEntry` is sufficient. ##### Remarks @@ -689,11 +689,6 @@ the filter. Release rules: The following sketch shows the minimum wiring for a client driver. ````c -// -// Global configuration block (or stored in driver context). -// -static DMF_BusFilter_CONFIG g_BusFilterConfig; - // // Optional: per-child callback. // @@ -767,12 +762,15 @@ DriverEntry( } // Initialize the bus filter library after WdfDriverCreate. + // The config struct can live on the stack: Initialize copies it internally + // and never reads the pointer again after it returns. // - DMF_BusFilter_CONFIG_INIT(&g_BusFilterConfig, DriverObject); - g_BusFilterConfig.EvtDeviceAdd = MyDriver_EvtDeviceAdd; - g_BusFilterConfig.EvtDeviceRemove = MyDriver_EvtDeviceRemove; + DMF_BusFilter_CONFIG busFilterConfig; + DMF_BusFilter_CONFIG_INIT(&busFilterConfig, DriverObject); + busFilterConfig.EvtDeviceAdd = MyDriver_EvtDeviceAdd; + busFilterConfig.EvtDeviceRemove = MyDriver_EvtDeviceRemove; - return DMF_BusFilter_Initialize(&g_BusFilterConfig); + return DMF_BusFilter_Initialize(&busFilterConfig); } ````