From: shitao Date: Mon, 7 Apr 2025 08:54:19 +0000 (+0800) Subject: ACPI: battery: Round capacity percengate to closest integer X-Git-Tag: v6.16-rc5~14^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=46d839adcc93ccc445f90866c31b2ed2785f0319;p=thirdparty%2Fkernel%2Flinux.git 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 Link: https://patch.msgid.link/20250407085419.494234-1-shitao@kylinos.cn [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- diff --git a/drivers/acpi/battery.c b/drivers/acpi/battery.c index 6760330a8af55..6905b56bf3e45 100644 --- a/drivers/acpi/battery.c +++ b/drivers/acpi/battery.c @@ -279,8 +279,8 @@ static int acpi_battery_get_property(struct power_supply *psy, full_capacity == ACPI_BATTERY_VALUE_UNKNOWN) ret = -ENODEV; else - val->intval = battery->capacity_now * 100/ - full_capacity; + val->intval = DIV_ROUND_CLOSEST_ULL(battery->capacity_now * 100ULL, + full_capacity); break; case POWER_SUPPLY_PROP_CAPACITY_LEVEL: if (battery->state & ACPI_BATTERY_STATE_CRITICAL)