Skip to content

Commit 92582c6

Browse files
andredgregkh
authored andcommitted
power: supply: max17042: avoid overflow when determining health
commit 9a44949 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: edd4ab0 ("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>
1 parent 27f7c02 commit 92582c6

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

drivers/power/supply/max17042_battery.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static int max17042_get_battery_health(struct max17042_chip *chip, int *health)
199199
goto out;
200200
}
201201

202-
if (vbatt > chip->pdata->vmax + MAX17042_VMAX_TOLERANCE) {
202+
if (vbatt > size_add(chip->pdata->vmax, MAX17042_VMAX_TOLERANCE)) {
203203
*health = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
204204
goto out;
205205
}

0 commit comments

Comments
 (0)