From 987954e18e3cdcc715190f12d0f0681699369d28 Mon Sep 17 00:00:00 2001 From: Jie Cheng Date: Thu, 4 Jun 2015 12:50:34 +0800 Subject: [PATCH] power: vm_bms: avoid a race condition in the calculate_reported_soc When the charging is ended, the last_soc may be set to invalid for a while. Add a check and do not calculate the reported soc if the last_soc value is invalid. Change-Id: Ia6987098dee5447c6852a276491930ddfbaa062e CRs-Fixed: 848209 Signed-off-by: Jie Cheng --- drivers/power/qpnp-vm-bms.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/power/qpnp-vm-bms.c b/drivers/power/qpnp-vm-bms.c index e0f5dd0d88d3..b24b34b41d27 100644 --- a/drivers/power/qpnp-vm-bms.c +++ b/drivers/power/qpnp-vm-bms.c @@ -1974,6 +1974,11 @@ static void calculate_reported_soc(struct qpnp_bms_chip *chip) { union power_supply_propval ret = {0,}; + if (chip->last_soc < 0) { + pr_debug("last_soc is not ready, return\n"); + return; + } + if (chip->reported_soc > chip->last_soc) { /*send DISCHARGING status if the reported_soc drops from 100 */ if (chip->reported_soc == 100) {