From 56b8e1f45ca3d779c87854630d56874171042114 Mon Sep 17 00:00:00 2001 From: Arun Murthy Date: Fri, 30 Sep 2011 12:59:59 +0530 Subject: power: ab5500-bm: handle divide by zero warning samples obtained from the fuel gauge is used to calculate the average current. Calculation of average current include division by samples, which ends up with division by zero in case samples is zero. Hence if samples is zero, average current is not calaulated and previous value is used. ST-Ericsson Linux next: NA ST-Ericsson ID: 363829 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I04dd205a7af07cfc7d2ff369fd29cdd1363f6208 Signed-off-by: Arun Murthy Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/32674 Reviewed-by: Rabin VINCENT --- drivers/power/ab5500_fg.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/power/ab5500_fg.c b/drivers/power/ab5500_fg.c index 0975c7417a4..62710680d1e 100644 --- a/drivers/power/ab5500_fg.c +++ b/drivers/power/ab5500_fg.c @@ -533,8 +533,12 @@ static void ab5500_fg_acc_cur_work(struct work_struct *work) di->fg_samples = (cnt_low | (cnt_high << 8)); val = (low | (med << 8) | (high << 16)); - di->accu_charge = (val * QLSB_NANO_AMP_HOURS_X10)/10000; - di->avg_curr = (val * FG_LSB_IN_MA) / (di->fg_samples * 1000); + if (di->fg_samples) { + di->accu_charge = (val * QLSB_NANO_AMP_HOURS_X10)/10000; + di->avg_curr = (val * FG_LSB_IN_MA) / (di->fg_samples * 1000); + } else + dev_err(di->dev, + "samples is zero, using previous calculated average current\n"); di->flags.conv_done = true; mutex_unlock(&di->cc_lock); -- cgit v1.2.3