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

power: supply: bq24190_charger: Disallow ccc_ireg and cvc_vreg to be higher then the fwnode values

If the fwnode data as parsed by power_supply_get_battery_info() provides
max values for ccc_ireg and cvc_vreg then do not allow the user to later
set these to higher values then those specified by the firmware,
otherwise the battery might get damaged.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Hans de Goede and committed by
Sebastian Reichel
4e456230 445c21d2

+8 -2
+8 -2
drivers/power/supply/bq24190_charger.c
··· 1019 1019 if (v) 1020 1020 curr *= 5; 1021 1021 1022 + if (curr > bdi->ichg_max) 1023 + return -EINVAL; 1024 + 1022 1025 ret = bq24190_set_field_val(bdi, BQ24190_REG_CCC, 1023 1026 BQ24190_REG_CCC_ICHG_MASK, BQ24190_REG_CCC_ICHG_SHIFT, 1024 1027 bq24190_ccc_ichg_values, ··· 1054 1051 const union power_supply_propval *val) 1055 1052 { 1056 1053 int ret; 1054 + 1055 + if (val->intval > bdi->vreg_max) 1056 + return -EINVAL; 1057 1057 1058 1058 ret = bq24190_set_field_val(bdi, BQ24190_REG_CVC, 1059 1059 BQ24190_REG_CVC_VREG_MASK, BQ24190_REG_CVC_VREG_SHIFT, ··· 1749 1743 /* These are optional, so no warning when not set */ 1750 1744 v = info->constant_charge_current_max_ua; 1751 1745 if (v >= bq24190_ccc_ichg_values[0] && v <= bdi->ichg_max) 1752 - bdi->ichg = v; 1746 + bdi->ichg = bdi->ichg_max = v; 1753 1747 1754 1748 v = info->constant_charge_voltage_max_uv; 1755 1749 if (v >= bq24190_cvc_vreg_values[0] && v <= bdi->vreg_max) 1756 - bdi->vreg = v; 1750 + bdi->vreg = bdi->vreg_max = v; 1757 1751 } 1758 1752 1759 1753 return 0;