power: pm8921-bms: handle null scaling factor tables
The scaling factor tables are based on aging of the battery. Sometimes
this data wont be available and these tables will be set to null.
Return 100% scaling factor when scaling factor table is missing.
Change-Id: I730813136d7c9fc10892a29f38449df19b5087a3
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/drivers/power/pm8921-bms.c b/drivers/power/pm8921-bms.c
index e498c03..a6251ff 100644
--- a/drivers/power/pm8921-bms.c
+++ b/drivers/power/pm8921-bms.c
@@ -631,18 +631,33 @@
static int interpolate_scalingfactor_fcc(struct pm8921_bms_chip *chip,
int cycles)
{
- return interpolate_single_lut(chip->fcc_sf_lut, cycles);
+ /*
+ * sf table could be null when no battery aging data is available, in
+ * that case return 100%
+ */
+ if (chip->fcc_sf_lut)
+ return interpolate_single_lut(chip->fcc_sf_lut, cycles);
+ else
+ return 100;
}
static int interpolate_scalingfactor_pc(struct pm8921_bms_chip *chip,
int cycles, int pc)
{
int i, scalefactorrow1, scalefactorrow2, scalefactor;
+ int rows, cols;
int row1 = 0;
int row2 = 0;
- int rows = chip->pc_sf_lut->rows;
- int cols = chip->pc_sf_lut->cols;
+ /*
+ * sf table could be null when no battery aging data is available, in
+ * that case return 100%
+ */
+ if (!chip->pc_sf_lut)
+ return 100;
+
+ rows = chip->pc_sf_lut->rows;
+ cols = chip->pc_sf_lut->cols;
if (pc > chip->pc_sf_lut->percent[0]) {
pr_debug("pc %d greater than known pc ranges for sfd\n", pc);
row1 = 0;