Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

power: supply: max17042: avoid overflow when determining health

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>

authored by

André Draszik and committed by
Sebastian Reichel
9a44949d 699f0f71

+1 -1
+1 -1
drivers/power/supply/max17042_battery.c
··· 201 201 goto out; 202 202 } 203 203 204 - if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) { 204 + if (vbatt > size_add(chip->pdata->vmax, MAX17042_VMAX_TOLERANCE)) { 205 205 *health = POWER_SUPPLY_HEALTH_OVERVOLTAGE; 206 206 goto out; 207 207 }