31 lines
1.4 KiB
Diff
31 lines
1.4 KiB
Diff
From f7ea8cad052a38b1571bfe03e079af55f1f7c2c1 Mon Sep 17 00:00:00 2001
|
|
From: Alexander Warnecke <awarnecke002@hotmail.com>
|
|
Date: Thu, 29 Jun 2023 19:52:42 +1000
|
|
Subject: [PATCH 399/464] 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>
|
|
---
|
|
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 8328bcea1a29..cae9064b2be0 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.34.1
|
|
|