google_bms: add GBMS_CCCM_LIMITS index check
when temperature >= stop charge criteria (55 degC), we set both temp_idx
and vbatt_idx to -1 in msc_logic_soft_jeita -> batt_reset_chg_drv_state
That causes invalid access in batt_calc_charging_speed -> GBMS_CCCM_LIMITS
Add index value check in GBMS_CCCM_LIMITS to prevent invalid access
Bug: 230744011
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: I0eb4637a42c70bd61a65099eee583d4f335da1ac
diff --git a/google_bms.h b/google_bms.h
index c47d53f..456ec02 100644
--- a/google_bms.h
+++ b/google_bms.h
@@ -362,9 +362,12 @@
struct gbms_ce_tier_stats trickle_stats;
};
-#define GBMS_CCCM_LIMITS(profile, ti, vi) \
+#define GBMS_CCCM_LIMITS_SET(profile, ti, vi) \
profile->cccm_limits[(ti * profile->volt_nb_limits) + vi]
+#define GBMS_CCCM_LIMITS(profile, ti, vi) \
+ (ti >= 0 && vi >= 0) ? profile->cccm_limits[(ti * profile->volt_nb_limits) + vi] : 0
+
/* newgen charging */
#define GBMS_CS_FLAG_BUCK_EN BIT(0)
#define GBMS_CS_FLAG_DONE BIT(1)