]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
power: supply: max17042: avoid overflow when determining health
authorAndré Draszik <andre.draszik@linaro.org>
Mon, 2 Mar 2026 13:32:05 +0000 (13:32 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 May 2026 13:31:15 +0000 (15:31 +0200)
commit 9a44949da669708f19d29141e65b3ac774d08f5a upstream.

If vmax has the default value of INT_MAX (e.g. because not specified in
DT), battery health is reported as over-voltage. This is because adding
any value to vmax (the vmax tolerance in this case) causes it to wrap
around, making it negative and smaller than the measured battery
voltage.

Avoid that by using size_add().

Fixes: edd4ab055931 ("power: max17042_battery: add HEALTH and TEMP_* properties support")
Cc: stable@vger.kernel.org
Signed-off-by: André Draszik <andre.draszik@linaro.org>
Link: https://patch.msgid.link/20260302-max77759-fg-v3-6-3c5f01dbda23@linaro.org
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/power/supply/max17042_battery.c

index acea176101fa88ff2e5a9187be17575c8278d097..a32ff503f45f79535a05a8726a9abcd7e5c6952f 100644 (file)
@@ -201,7 +201,7 @@ static int max17042_get_battery_health(struct max17042_chip *chip, int *health)
                goto out;
        }
 
-       if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) {
+       if (vbatt > size_add(chip->pdata->vmax, MAX17042_VMAX_TOLERANCE)) {
                *health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
                goto out;
        }