From abeea59fe2137f4a00758b19e405c140e8a3f659 Mon Sep 17 00:00:00 2001
From: Alexander Warnecke <awarnecke002@hotmail.com>
Date: Thu, 29 Jun 2023 19:52:42 +1000
Subject: [PATCH 407/463] power: supply: rk817-charger: 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>
---
 drivers/power/supply/rk817_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/rk817_charger.c b/drivers/power/supply/rk817_charger.c
index 7ca91739c6ccf..44af88045ac1f 100644
--- a/drivers/power/supply/rk817_charger.c
+++ b/drivers/power/supply/rk817_charger.c
@@ -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);
-- 
2.46.0

