Dear Maintainer,
On systems with broken battery controllers, ACPI may report an invalid battery
capacity value, specifically `-NaN`. This causes `upowerd` to crash repeatedly
due to an invalid gdouble being passed to `g_object_set`.
This leads to system instability or continuous reboots due to repeated crashes
of systemd-managed services.
The following patch adds a basic sanity check to clamp invalid values to 0.0.
--- PATCH START ---
--- upower-1.90.3.orig/src/linux/up-device-supply.c
+++ upower-1.90.3/src/linux/up-device-supply.c
@@ -313,6 +313,11 @@ up_device_supply_refresh_device (UpDevic
if (percentage == 100.0)
state = UP_DEVICE_STATE_FULLY_CHARGED;
+ if (!isfinite(percentage) || percentage < 0.0 || percentage > 100.0) {
+ g_warning("Invalid percentage value: %f, setting to 0.0", percentage);
+ percentage = 0.0;
+ }
+
g_object_set (device,
"percentage", percentage,
"battery-level", level,
--- PATCH END ---
Tested on affected system; no crash occurs after patch is applied.
Regards,
Renkas Mykhailo
Hi Am 27.07.25 um 12:13 schrieb Renkas Mykhailo: It would be great if you can submit a merge request upstream at https://gitlab.freedesktop.org/upower/upower We avoid applying patches downstream as much as possible, especially if the issue is not Debian specific. Regards, Michael
Hi I agree with Michael, and would actually suggest opening an issue instead of a pull request, so the problem can be investigated properly. Incidentally, this code should only run for powered peripherals, not the system power supply. So it should most likely not be triggered by ACPI, buggy or not. As a result, I do not expect upower folk to merge the patch as is. While it would seem to be working, it is likely masking a bigger issue that warrants a proper fix, perhaps even outside upower itself, e.g. kernel. Sincerely, Sicelo
Hi Am 27.07.25 um 19:45 schrieb Sicelo: Thanks a lot for your input, Sicelo! Your suggestion to open an issue first is indeed a reasonable one. As I expect follow-up questions, it is best if you do that directly Renkas, as I can't reproduce the issue myself given it's hardware specific. I'm tentatively removing the patch tag Regards, Michael
Hi Renkas, Michael, There appears to be a fix that landed in v1.91.1 of upower (the bugfix has git commit ID 988624350b5c29818c0ee0114f16ace011767165) to resolve upower crashes due to this NaN issue: https://gitlab.freedesktop.org/upower/upower/-/merge_requests/306 However: see also Debian bug #1114796; it describes excessive log output and seems similar/related. Those log messages continue to appear on my affected system running v1.91.2 of upowerd. Regards, James
Version: 1.19.1-1 Thanks, closing this particular bug report for this version. Michael