ACPI: Always return valid 'status' from acpi_battery_get_property()
If a battery is at a critical charge level and not being charged or discharged, then the ACPI _BST method will return a state of 4, and the current acpi_battery_get_property() code will not set any property value for POWER_SUPPLY_PROP_STATUS. This will cause an oops in power_supply_show_property() when it reads off the end of the status_text array. This actually was causing a 100% reproducible crash on boot on my laptop with two batteries, when one battery was completely drained and the laptop was not plugged in.
Fix this by making sure acpi_battery_get_property() returns POWER_SUPPLY_STATUS_UNKNOWN for any battery state it doesn't already handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.
---
drivers/acpi/battery.c +2 -0
@@ -152,6 +152,8 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval =POWER_SUPPLY_STATUS_CHARGING ; else if (battery->state == 0) val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_UNKNOWN;break ;case POWER_SUPPLY_PROP_PRESENT : val->intval =acpi_battery_present (battery);
Alexey Starikovskiy
Acked-byThanks,
Alex.
Quoted 9 lines · Roland Dreier
If a battery is at a critical charge level and not being charged or discharged, then the ACPI
_BSTmethod will return a state of 4, and the currentacpi_battery_get_property()code will not set any property value forPOWER_SUPPLY_PROP_STATUS. This will cause an oops inpower_supply_show_property()when it reads off the end of thestatus_textarray. This actually was causing a 100% reproducible crash on boot on my laptop with two batteries, when one battery was completely drained and the laptop was not plugged in.
Quoted 7 lines
Fix this by making sure
acpi_battery_get_property()returnsPOWER_SUPPLY_STATUS_UNKNOWNfor any battery state it doesn't already handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.Signed-off-by Roland Dreier <[email protected]>
Quoted 14 lines
---
drivers/acpi/battery.c +2
-0@@ -152,6 +152,8 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval =POWER_SUPPLY_STATUS_CHARGING ; else if (battery->state == 0) val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_UNKNOWN;break ;case POWER_SUPPLY_PROP_PRESENT : val->intval =acpi_battery_present (battery);
Quoted 3 lines · Alexey Starikovskiy
Quoted 3 lines
handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.
Maybe one should be added?
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 4 lines · Alexey Starikovskiy
Quoted 4 lines
handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.
Maybe one should be added?
There is already "Critical" field for capacity.
It seems that the state should be limited to only 3 options:
charging, discharging, and not charging.
Regards,
Alex.
ACPI: Battery: Always return valid 'status' from get_property
From: Alexey Starikovskiy <[email protected]>
---
drivers/acpi/battery.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/acpi/battery.c +2 -2
@@ -151,8 +151,8 @@ static int acpi_battery_get_property(struct power_supply *psy, val->intval =POWER_SUPPLY_STATUS_DISCHARGING ; else if (battery->state & 0x02) val->intval = POWER_SUPPLY_STATUS_CHARGING; - else if (battery->state == 0) - val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;break ;case POWER_SUPPLY_PROP_PRESENT : val->intval =acpi_battery_present (battery);
Quoted 9 lines · Alexey Starikovskiy
Quoted 7 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Alexey Starikovskiy
Quoted 3 lines
handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.
Maybe one should be added?
There is already "Critical" field for capacity.
Ah, that's ok, then.
Quoted 2 lines
It seems that the state should be limited to only 3 options:
charging, discharging, and not charging.
I'd call "not charging", "idle" instead. After all, discharging IS not charging as well...
Signature · 4 lines
"One disk to rule them all, One disk to find them. One disk to bring them all and in the darkness grind them. In the Land of Redmond where the shadows lie." -- The Silicon Valley Tarot Henrique Holschuh
Quoted 10 lines · Henrique de Moraes Holschuh
Quoted 8 lines · Alexey Starikovskiy
Quoted 6 lines · Henrique de Moraes Holschuh
Quoted 3 lines · Alexey Starikovskiy
Quoted 3 lines
handle explicitly. There doesn't seem to be any status enum value defined that makes more sense than 'unknown' for a battery at a critical charge level.
Maybe one should be added?
There is already "Critical" field for capacity.
Quoted 8 lines
Ah, that's ok, then.
Quoted 2 lines
It seems that the state should be limited to only 3 options:
charging, discharging, and not charging.I'd call "not charging", "idle" instead. After all, discharging IS not charging as well...
There is power_supply interface, and authors already declared this "not charging" state, also they already failed to invent "idle". So, you might send them patch, renaming "not charging" to "idle"...
Regards,
Alex.