supply: rk817: Fix battery capacity sanity check calculation

If the nvram variable is corrupted in a way that multiplying it by 1000 causes an integer overflow and wraps around to a number within or below the sanity check bounds, the check fails and capacity is reported incorrectly.
Change the sanity check calculation to not multiply the variable read from the rk817 nvram, preventing the overflow and resulting in all corrupt capacity values being detected.

Signed-off-by: Alexander Warnecke <awarnecke002@hotmail.com>
This commit is contained in:
Alexander Warnecke
2023-06-29 19:52:42 +10:00
committed by Mauro (mdrjr) Ribeiro
parent 8a380517b4
commit 9072f9d428

View File

@@ -715,7 +715,7 @@ static int rk817_read_battery_nvram_values(struct rk817_charger *charger)
* correct it.
*/
if ((charger->fcc_mah < 500) ||
((charger->fcc_mah * 1000) > charger->bat_charge_full_design_uah)) {
(charger->fcc_mah > (charger->bat_charge_full_design_uah / 1000))) {
dev_info(charger->dev,
"Invalid NVRAM max charge, setting to %u uAH\n",
charger->bat_charge_full_design_uah);