Skip to content

Commit 46d839a

Browse files
shitaorafaeljw
authored andcommitted
ACPI: battery: Round capacity percengate to closest integer
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 <[email protected]> Link: https://patch.msgid.link/[email protected] [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 0af2f6b commit 46d839a

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)