From 881e346bc606ae16567658fe5d76f63f1d27daf5 Mon Sep 17 00:00:00 2001 From: liuyc20 Date: Wed, 22 Dec 2021 11:08:05 +0800 Subject: [PATCH] FG: RT9426A add safeguard for ocv_index ocv_index is used for ocv_table parameter. In some case read a invalid ocv_indes(65535/-13),then driver read the wrong ocv parameter, that make checksum fail and exit the driver. the ocv_index only 0~4 is valid, if read a invalid ocv_index, using the default ocv_index to fix above issue. Change-Id: I633aaa7f9abc4a98abb72cbec45025c8c52d5662 Signed-off-by: liuyc20 Reviewed-on: https://gerrit.mot.com/2151514 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Huosheng Liao Submit-Approved: Jira Key --- drivers/power/rt9426a_fg_mmi/rt9426a_battery.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c b/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c index 01bbe4e21fde..cc113f0b2cee 100644 --- a/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c +++ b/drivers/power/rt9426a_fg_mmi/rt9426a_battery.c @@ -2285,11 +2285,17 @@ static int rt9426a_apply_pdata(struct rt9426a_chip *chip) u8 page_idx=0,extend_reg_cmd_addr=0, array_idx=0; int volt_now = 0, fd_vth_now = 0, fd_threshold = 0; int wt_ocv_result = RT9426A_WRITE_OCV_FAIL; + int ocv_index = 0; dev_info(chip->dev, "%s\n", __func__); /* read ocv_index before using it */ - chip->ocv_index = rt9426a_reg_read_word(chip->i2c, RT9426A_REG_RSVD2); + ocv_index = rt9426a_reg_read_word(chip->i2c, RT9426A_REG_RSVD2); + /* ocv_index only 0~4 is valid, if read a invalid ocv_index, using the default ocv_index */ + if (ocv_index < 0 || ocv_index > 4) + chip->ocv_index = 0; + else + chip->ocv_index = ocv_index; dev_info(chip->dev, "%s: ocv_index = %d\n", __func__, chip->ocv_index); /* update ocv_checksum_dtsi after ocv_index updated */