mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] power: supply: surface_battery: Defer AC-triggered update across suspend
@ 2026-11-17  3:49 Ricky Sorrell via B4 Relay
  0 siblings, 0 replies; only message in thread
From: Ricky Sorrell via B4 Relay @ 2026-11-17  3:49 UTC (permalink / raw)
  To: Maximilian Luz, Sebastian Reichel
  Cc: linux-pm, platform-driver-x86, linux-kernel, Ricky Sorrell

From: Ricky Sorrell <rmsorrell@gmail.com>

When the AC adapter is plugged in or removed, spwr_external_power_changed()
schedules a battery state update after five seconds, on system_wq. That
workqueue is not frozen for system suspend. If the system starts to
suspend within those five seconds, for example when the charger is
unplugged and the lid closed straight away, the work runs after the
Surface Aggregator controller has been suspended. The request then trips
the WARN_ON() in ssam_request_do_sync_with_buffer() and fails:

  WARNING: drivers/platform/surface/aggregator/controller.c:1703 at ssam_request_do_sync_with_buffer+0x15a/0x180 [surface_aggregator]
  Workqueue: events spwr_battery_update_bst_workfn [surface_battery]
  surface_battery 01:02:02:01:00: failed to update battery state: -19

Queue the work on system_freezable_wq instead. Freezable workqueues are
frozen before devices are suspended and thawed after they have resumed,
so a pending update now runs only once the controller is reachable again.
Nothing is lost by the delay: surface_battery_resume() already rechecks
the full battery state.

The problem was found, and this change written and tested, with the help
of an AI coding assistant (Claude Opus 5.5 in Claude Code). It was found
by reading the kernel log after suspend tests on a Surface Book 3, then
confirmed in the source. Reproduced and tested on a Surface Book 3 with
Linux 7.3.4: unplug the charger and close the lid within five seconds.
Before the change the warning above appeared; after it, the same test
gave no warning and correct battery state after resume.

Fixes: 167f77f7d0b3 ("power: supply: Add battery driver for Surface Aggregator Module")
Signed-off-by: Ricky Sorrell <rmsorrell@gmail.com>
---
Not done, so reviewers know: the change was built and tested against
Linux 7.3.4 only. Mainline's surface_battery.c differs from 7.3.4 only in
an unrelated devm_kzalloc_obj() line, and the patch applies to mainline,
but it was not built or run there.
---
 drivers/power/supply/surface_battery.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/surface_battery.c b/drivers/power/supply/surface_battery.c
index dac19932c..a9b0cdfe3 100644
--- a/drivers/power/supply/surface_battery.c
+++ b/drivers/power/supply/surface_battery.c
@@ -417,9 +417,14 @@ static void spwr_external_power_changed(struct power_supply *psy)
 	 * event for the state (charging/discharging) change. Furthermore it
 	 * may take some time until the state is updated on the battery.
 	 * Schedule an update to solve this.
+	 *
+	 * Use the freezable workqueue so that the update does not run while
+	 * the system is suspending, when the EC can no longer be reached.
+	 * surface_battery_resume() rechecks the full state anyway.
 	 */
 
-	schedule_delayed_work(&bat->update_work, SPWR_AC_BAT_UPDATE_DELAY);
+	queue_delayed_work(system_freezable_wq, &bat->update_work,
+			   SPWR_AC_BAT_UPDATE_DELAY);
 }
 
 

---
base-commit: 666539eecdf4db623f5e3c3e55cf9f2dfad24aa4
change-id: 20261116-surface-battery-suspend-b5adbbfe80af

Best regards,
--  
Ricky Sorrell <rmsorrell@gmail.com>



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17  3:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  3:49 [PATCH] power: supply: surface_battery: Defer AC-triggered update across suspend Ricky Sorrell via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®