Acer Nitro V15 battery charge level protection and Ubuntu

The Nitro V15 supports battery protection via min/max charge levels, but Ubuntu doesn’t talk the hardware protocol out of the box. There’s a kernel module which enables charge levels. I’m a bit in a hurry, so the TLD:

  1. the module is here https://github.com/frederik-h/acer-wmi-battery
    check it out and follow the installation instructions
  2. Tried & works under Ubuntu 24.04
  3. An AI review found a bug in acer-wmi-battery.c, you might want to fix that:
diff --git a/acer-wmi-battery.c b/acer-wmi-battery.c
index a9b0924..8e6431b 100644
--- a/acer-wmi-battery.c
+++ b/acer-wmi-battery.c
@@ -153,15 +153,16 @@ get_battery_health_control_status(struct battery_info *bat_status)
return AE_ERROR;
}
- ret = *((struct get_battery_health_control_status_output *)
- obj->buffer.pointer);
- if (obj->buffer.length != 8) {
+ if (obj->buffer.length != sizeof(struct get_battery_health_control_status_output)) {
pr_err("WMI battery status call returned a buffer of "
"unexpected length %d\n", obj->buffer.length);
kfree(obj);
return AE_ERROR;
}
+ ret = *((struct get_battery_health_control_status_output *)
+ obj->buffer.pointer);
+
bat_status->health_mode = ret.uFunctionList & HEALTH_MODE ?
ret.uFunctionStatus[0] > 0 :
-1;
@@ -208,13 +209,13 @@ static acpi_status set_battery_health_control(u8 function, bool function_status)
return AE_ERROR;
}
- ret = *((struct set_battery_health_control_output *)obj->buffer.pointer);
-
if (obj->buffer.length != 4) {
pr_err("WMI battery status set operation returned "
"a buffer of unexpected length %d\n",
obj->buffer.length);
status = AE_ERROR;
+ } else {
+ ret = *((struct set_battery_health_control_output *)obj->buffer.pointer);
}
kfree(obj);

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.