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

power: supply: max17042_battery: Prevent int underflow in set_soc_threshold

max17042_set_soc_threshold gets called with offset set to 1, which means
that minimum threshold value would underflow once SOC got down to 0,
causing invalid alerts from the gauge.

Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC")
Cc: <stable@vger.kernel.org>
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Sebastian Krzyszkowiak and committed by
Sebastian Reichel
e660dbb6 0cf48167

+2 -1
+2 -1
drivers/power/supply/max17042_battery.c
··· 860 860 regmap_read(map, MAX17042_RepSOC, &soc); 861 861 soc >>= 8; 862 862 soc_tr = (soc + off) << 8; 863 - soc_tr |= (soc - off); 863 + if (off < soc) 864 + soc_tr |= soc - off; 864 865 regmap_write(map, MAX17042_SALRT_Th, soc_tr); 865 866 } 866 867