diff options
author | Jenny Ho <hsiufangho@google.com> | 2024-02-05 20:41:07 +0800 |
---|---|---|
committer | Jenny Ho <hsiufangho@google.com> | 2024-02-06 05:14:57 +0000 |
commit | ca968b94232236e59ecf16d81492e4d25f94f4cc (patch) | |
tree | 1fccc5a026276e0f2d16fc3ff77626e3a9720621 | |
parent | c9447124bc4c266276dd4f9151e6c91fa8148cd2 (diff) | |
download | bms-ca968b94232236e59ecf16d81492e4d25f94f4cc.tar.gz |
max1720x_battery: check gauge_type before accessing max_m5 functions
This file handles both max77759 and max17201 FG, only max77759 FG allows
accesses to max_m5 related functions, adds gauge type checking to prevent kernel panic
Bug: 318106590
Change-Id: Ia5d5301cb2db4304ace2d3acc2d5d3b2c6c39c25
Signed-off-by: Jenny Ho <hsiufangho@google.com>
(cherry picked from commit 36c2a4d58e3e3ef1440dcc6512ae73b7b7d18559)
-rw-r--r-- | max1720x_battery.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/max1720x_battery.c b/max1720x_battery.c index 63349e1..d27896e 100644 --- a/max1720x_battery.c +++ b/max1720x_battery.c @@ -1658,7 +1658,8 @@ static int max1720x_update_cycle_count(struct max1720x_chip *chip) return -ECANCELED; /* if cycle reg hasn't been restored from storage, restore it before update cycle count */ - if (!chip->cycle_reg_ok && max_m5_recal_state(chip->model_data) == RE_CAL_STATE_IDLE) { + if (!chip->cycle_reg_ok && chip->gauge_type == MAX_M5_GAUGE_TYPE && + max_m5_recal_state(chip->model_data) == RE_CAL_STATE_IDLE) { err = max1720x_restore_battery_cycle(chip); if (err < 0) dev_err(chip->dev, "%s cannot restore cycle count (%d)\n", __func__, err); |