Skip to content

bugfix/wdfserial: preserve user's power management choice across reboots - #109

Merged
Chenxi Han (5656hcx) merged 2 commits into
qualcomm:developfrom
CristianManca:fix/wdfserial-idle-power-management-persistence
Sep 9, 2026
Merged

Chenxi Han (5656hcx) merged 2 commits into
qualcomm:developfrom
CristianManca:fix/wdfserial-idle-power-management-persistence

Conversation

@CristianManca

Copy link
Copy Markdown
Contributor

Description

Fixes the "Allow the computer to turn off this device to save power"
checkbox resetting to enabled on every reboot/USB re-enumeration.
Fixes #108 .

Root Cause

QCPNP_EnableSelectiveSuspend() unconditionally forced Enabled = WdfTrue
on every call, including at device initialization (EvtDevicePrepareHardware).
This overwrote the value WDF persists per-device in the registry
(Device Parameters\WDF\IdleInWorkingState), which backs the checkbox state.

Additionally, using explicit WdfTrue bypassed WDF's initial-default
lookup of WdfDefaultIdleInWorkingState (INF-provided) on first device
installation, forcing IdleInWorkingState = 1 regardless of any default.

Changes

  • Added HonorPersistedUserChoice parameter to QCPNP_EnableSelectiveSuspend:
    • Boot/re-enum path: passes TRUE → uses WdfUseDefault, letting WDF
      re-apply the persisted user choice instead of forcing it on
    • Runtime WMI toggle handlers: pass FALSE → explicit WdfTrue/WdfFalse,
      so fresh user choices take effect immediately
    • HW-forced disable (SAHARA/FIREHOSE/LPC) still wins via explicit WdfFalse
  • Added QCPNP_SyncPersistedIdleEnabledState(): read-only sync of the driver's
    internal PowerManagementEnabled flag with the actual IdleInWorkingState
    registry value after boot, so the driver's own Power Management checkbox
    query reports the real persisted state instead of a stale default

No new registry keys introduced; IdleInWorkingState is never written by
the driver.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Hotfix (urgent fix targeted at a release/x.y branch)
  • Refactor (no functional change)
  • Performance improvement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Test-only change
  • CI / build-pipeline change

How has this been tested?

Hardware validation on x64 laptop + USB modem (Windows 11 25H2):

  1. Persistence across reboot: disabled the checkbox, rebooted, verified
    it remained disabled in Device Manager.
  2. Runtime toggle: re-enabled the checkbox at runtime (via Device Manager),
    verified it took effect immediately without regression.
  3. Build validation: project built successfully with Visual Studio 2022
    targeting Windows 11; no new compiler warnings or WPP trace errors.
  4. Device logs: pre-fix and post-fix ETW traces confirmed
    the new code path (WdfUseDefault on boot, explicit values on WMI toggle) executed as designed.

Checklist

  • All required CI checks are green on the latest commit of this PR
  • Build succeeds following the steps in the README
  • My code follows the Code Style Guidelines of this project
  • My branch follows the naming convention: fix/wdfserial-idle-power-management-persistence
  • PR title follows the Conventional Commits format with our full-word types
  • I have performed a self-review of my own code
  • I have added code comments in areas that are complex or hard to understand
  • My changes generate no new compiler warnings
  • I have added tests for my fix or feature (hardware validation on real device; kernel driver unit testing via ETW logs)
  • New and existing tests pass locally with my changes
  • My branch is rebased onto the latest develop - no merge commits
  • Every commit has Signed-off-by: (DCO) - will be added at merge
  • I have linked the relevant issue if any (Fixes [wdfserial] "Allow the computer to turn off this device" checkbox resets after USB re-enumeration #108 )
  • Any dependent changes have been merged and published in downstream modules (N/A)

BUG: the "Allow the computer to turn off this device to save
power" checkbox reset to enabled after every reboot/re-enumeration,
because QCPNP_EnableSelectiveSuspend always forced Enabled=WdfTrue,
overwriting the persisted user choice stored by WDF in
Device Parameters\WDF\IdleInWorkingState.

- Add HonorPersistedUserChoice parameter to
  QCPNP_EnableSelectiveSuspend: boot/re-enum path
  (QCPNP_EvtDevicePrepareHardware) now passes TRUE, letting WDF apply
  WdfUseDefault and re-read the persisted value instead of forcing it
  on; runtime WMI toggle handlers (QCPNP_PMSetWmiDataItem/DataBlock)
  pass FALSE to apply the fresh WdfTrue/WdfFalse choice immediately.
- HW-forced disable (SAHARA/FIREHOSE/LPC) still always wins via
  explicit WdfFalse, regardless of caller.
- Add QCPNP_SyncPersistedIdleEnabledState: after WdfUseDefault is
  applied at boot, re-sync pDevContext->PowerManagementEnabled with
  the actual IdleInWorkingState registry value (read-only, no new
  registry keys) so the driver's own Power Management checkbox
  (QCPNP_PMQueryWmiDataBlock/DataItem) no longer shows a stale
  "enabled" state that mismatches what was actually persisted.

Signed-off-by: Cristian Manca <Cristian.Manca@telit.com>
Comment thread src/windows/wdfserial/QCPNP.c Outdated
Comment thread src/windows/wdfserial/QCPNP.c
…boot

Move QCPNP_SyncPersistedIdleEnabledState() from the boot path
(QCPNP_EnableSelectiveSuspend) into QCPNP_PMQueryWmiDataBlock, so the
persisted IdleInWorkingState registry value is read only when the
Power Management page queries the WMI data block, not on every boot.

PowerManagementEnabled is reset to TRUE on every device
(re-)initialization, so syncing only at boot left the GUI checkbox
stale vs. the actual persisted value. Windows also echoes the
displayed value back on page close, so the stale TRUE was silently
overwriting IdleInWorkingState. On-demand sync keeps the GUI fresh,
removes registry I/O from the boot path, and prevents the
close-triggered overwrite.

Skip the sync for SAHARA/FIREHOSE/LPC (same guard as in
QCPNP_EvtDevicePrepareHardware), since PowerManagementEnabled is
hardware-forced for those and not registry-backed

Signed-off-by: Cristian Manca <Cristian.Manca@telit.com>
@5656hcx Chenxi Han (5656hcx) self-assigned this Sep 3, 2026
@5656hcx Chenxi Han (5656hcx) added the enhancement New feature or request label Sep 3, 2026
@CristianManca Cristian Manca (CristianManca) changed the title fix(wdfserial): preserve user's power management choice across reboots bugfix(wdfserial): preserve user's power management choice across reboots Sep 7, 2026
@CristianManca Cristian Manca (CristianManca) changed the title bugfix(wdfserial): preserve user's power management choice across reboots bugfix/wdfserial: preserve user's power management choice across reboots Sep 8, 2026
@5656hcx
Chenxi Han (5656hcx) merged commit 671d5df into qualcomm:develop Sep 9, 2026
41 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wdfserial] "Allow the computer to turn off this device" checkbox resets after USB re-enumeration

2 participants