linux/drivers/power/supply
Dorian Rudolph 093d27bb6f power: supply: core: Fix boundary conditions in interpolation
The functions power_supply_temp2resist_simple and power_supply_ocv2cap_simple
handle boundary conditions incorrectly.
The change was introduced in a4585ba205
("power: supply: core: Use library interpolation").
There are two issues: First, the lines "high = i - 1" and "high = i" in ocv2cap
have the wrong order compared to temp2resist. As a consequence, ocv2cap
sets high=-1 if ocv>table[0].ocv, which causes an out-of-bounds read.
Second, the logic of temp2resist is also not correct.
Consider the case table[] = {{20, 100}, {10, 80}, {0, 60}}.
For temp=5, we expect a resistance of 70% by interpolation.
However, temp2resist sets high=low=2 and returns 60.

Cc: stable@vger.kernel.org
Signed-off-by: Dorian Rudolph <mail@dorianrudolph.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Fixes: a4585ba205 ("power: supply: core: Use library interpolation")
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-06-09 21:08:38 +02:00
..
88pm860x_battery.c
88pm860x_charger.c
ab8500_bmdata.c
ab8500_btemp.c
ab8500_chargalg.c
ab8500_charger.c
ab8500_fg.c power: supply: ab8500_fg: add missing destroy_workqueue in ab8500_fg_probe 2022-06-09 21:08:06 +02:00
ab8500-bm.h
ab8500-chargalg.h
acer_a500_battery.c
act8945a_charger.c
adp5061.c
apm_power.c
axp20x_ac_power.c
axp20x_battery.c
axp20x_usb_power.c
axp288_charger.c
axp288_fuel_gauge.c
bd99954-charger.c
bd99954-charger.h
bq27xxx_battery_hdq.c
bq27xxx_battery_i2c.c
bq27xxx_battery.c
bq256xx_charger.c
bq2415x_charger.c
bq2515x_charger.c
bq24190_charger.c
bq24257_charger.c
bq24735-charger.c
bq25890_charger.c
bq25980_charger.c
bq25980_charger.h
charger-manager.c
collie_battery.c
cpcap-battery.c
cpcap-charger.c
cros_peripheral_charger.c
cros_usbpd-charger.c
cw2015_battery.c
da9030_battery.c
da9052-battery.c
da9150-charger.c
da9150-fg.c
ds2760_battery.c
ds2780_battery.c
ds2781_battery.c
ds2782_battery.c
generic-adc-battery.c
goldfish_battery.c
gpio-charger.c
ingenic-battery.c
ip5xxx_power.c
ipaq_micro_battery.c
isp1704_charger.c
Kconfig
lego_ev3_battery.c
lp8727_charger.c
lp8788-charger.c
lt3651-charger.c
ltc2941-battery-gauge.c
ltc4162-l-charger.c
Makefile
max1721x_battery.c
max8903_charger.c
max8925_power.c
max8997_charger.c
max8998_charger.c
max14577_charger.c
max14656_charger_detector.c
max17040_battery.c
max17042_battery.c
max77650-charger.c
max77693_charger.c
max77976_charger.c
mp2629_charger.c
mt6360_charger.c
olpc_battery.c
pcf50633-charger.c
pda_power.c
pm2301_charger.h
pmu_battery.c
power_supply_core.c power: supply: core: Fix boundary conditions in interpolation 2022-06-09 21:08:38 +02:00
power_supply_hwmon.c
power_supply_leds.c
power_supply_sysfs.c
power_supply.h
qcom_smbb.c
rn5t618_power.c
rt5033_battery.c
rt9455_charger.c
rx51_battery.c
s3c_adc_battery.c
samsung-sdi-battery.c
samsung-sdi-battery.h
sbs-battery.c
sbs-charger.c
sbs-manager.c
sc27xx_fuel_gauge.c
sc2731_charger.c
smb347-charger.c
surface_battery.c
surface_charger.c
test_power.c
tosa_battery.c
tps65090-charger.c
tps65217_charger.c
twl4030_charger.c
twl4030_madc_battery.c
ucs1002_power.c
ug3105_battery.c
wilco-charger.c
wm97xx_battery.c
wm831x_backup.c
wm831x_power.c
wm8350_power.c
z2_battery.c