summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Murthy <arun.murthy@stericsson.com>2011-09-30 12:59:59 +0530
committerRabin VINCENT <rabin.vincent@stericsson.com>2011-10-04 12:14:20 +0200
commit56b8e1f45ca3d779c87854630d56874171042114 (patch)
tree41ab57b1dcc824074aca712c816a2a9eff6b6696
parent882f46dab7bc2b3122a7ac219f691330b6aed9bf (diff)
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 <arun.murthy@stericsson.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/32674 Reviewed-by: Rabin VINCENT <rabin.vincent@stericsson.com>
-rw-r--r--drivers/power/ab5500_fg.c8
1 files 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);