Skip to content

Commit 24a5320

Browse files
committed
ACPI: battery: Round capacity percengate to closest integer
JIRA: https://issues.redhat.com/browse/RHEL-114091 commit 46d839a Author: shitao <shitao@kylinos.cn> Date: Wed, 09 Apr 2025 15:56:19 +0000 If the difference between capacity_now and full_capacity is within 0.5%, 100% is arguably a better number to expose than 99% and exposing the latter may confuse the user to think that there's something wrong with the battery. Round the capacity percentage to the closest integer value to avoid the confusion. Signed-off-by: shitao <shitao@kylinos.cn> Link: https://patch.msgid.link/20250407085419.494234-1-shitao@kylinos.cn [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent 157e1a0 commit 24a5320

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/acpi/battery.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ static int acpi_battery_get_property(struct power_supply *psy,
279279
full_capacity == ACPI_BATTERY_VALUE_UNKNOWN)
280280
ret = -ENODEV;
281281
else
282-
val->intval = battery->capacity_now * 100/
283-
full_capacity;
282+
val->intval = DIV_ROUND_CLOSEST_ULL(battery->capacity_now * 100ULL,
283+
full_capacity);
284284
break;
285285
case POWER_SUPPLY_PROP_CAPACITY_LEVEL:
286286
if (battery->state & ACPI_BATTERY_STATE_CRITICAL)

0 commit comments

Comments
 (0)