power: pm8921-bms: fix divide by 0 issue when charging
The current code can divide by zero in the scale_soc_while_chg
function if calculated_soc drops while charging.
Fix the issue by not scaling soc if catch_up_time_us is zero.
CRs-Fixed: 418419
Change-Id: I9f38515f35fcddfbdc34ae4f59ffcfc6682033d4
Signed-off-by: Xiaozhe Shi <xiaozhes@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index a189a85..1b40753 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -2425,7 +2425,8 @@
}
/* last_soc < soc ... scale and catch up */
- if (last_soc != -EINVAL && last_soc < soc && soc != 100)
+ if (last_soc != -EINVAL && last_soc < soc && soc != 100
+ && chip->catch_up_time_us != 0)
soc = scale_soc_while_chg(chip, delta_time_us, soc, last_soc);
last_soc = soc;