Skip to content

power: supply: macsmc: set up work before the notifier, and wait for it at remove - #2987

Draft
Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/macsmc-power-remove
Draft

Alyx-ML wants to merge 1 commit into
aurora-silicon:integration/aurorafrom
Alyx-ML:aurora/macsmc-power-remove

Conversation

@Alyx-ML

@Alyx-ML Alyx-ML commented Nov 23, 2026

Copy link
Copy Markdown

Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which).

Summary

 probe
-  register notifier;  INIT_WORK(critical_work) again;  set up dbg_log_work
+  set up dbg_log_work;  register notifier     # nothing can queue work that is not set up
 remove
-  cancel_work();  cancel_delayed_work();  unregister notifier
+  unregister notifier;  g_power = NULL
+  disable_delayed_work_sync(dbg_log_work)     # it re-arms itself, so disable, then wait
+  cancel_work_sync(critical_work)

Probe still keeps the firmware charge settings (b8e84d0), and now logs a CHLS_HOLD it finds
with no known limit.

Evidence

  • Before: an event during probe could have its queued work reset under it, and the debug work
    could run after devm freed the driver state (found by reading against the workqueue and devm
    helpers).
  • After: build and KUnit (macsmc, which includes the macsmc-power tests):
    passed, Apple build and KUnit. Those tests have no probe or remove case.
  • Needed before merging: on a MacBook, a boot, the battery readout, and unbinding and binding
    macsmc-power again.

Merge Danger

Door: two-way

Blast Radius: battery reporting

Assisted-by: LLM (Claude:Opus 5.5)

…it at remove

Probe registered the SMC notifier and then ran INIT_WORK() on
critical_work again. devm_work_autocancel() had already set it up. An
SMC critical-battery event that came in between could have its queued
work reset under it. dbg_log_work was set up only after the notifier.
Remove used cancel_work() and cancel_delayed_work(), which do not wait,
and unregistered the notifier last. The debug work re-arms itself, so it
could run, or queue itself again, after devm had freed the driver state.

Set up both work items before anything can queue them, and drop the
second INIT_WORK(). At remove, unregister the notifier and clear g_power
first. Then disable_delayed_work_sync() the debug work and
cancel_work_sync() the critical work.

Two comments say what stays as it is. Probe does not reset the charge
inhibitors, as commit b8e84d0 ("power: supply: macsmc: Preserve
firmware charge settings at probe") decided. The user's CHLS limit
during a CHLS_HOLD is kept in RAM only, so a hold found at probe has no
known limit. Probe now logs that case.

Verified: read against the workqueue and devm helpers. Not compiled or run
here (macOS host). KUnit for this file has no probe or remove case.

Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant