google_battery: fix invalid-access in GBMS_CCCM_LIMITS

temp_idx and vbatt_idx are -1 when battery is disconnected. And
this situation results in invalid access to the CCCM table. Move
to a reasonable position to check cc_max

Bug: 228802503
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: I9d41714d91e5ccb25abe66c4fc1920be0d2851d4
diff --git a/google_battery.c b/google_battery.c
index d50e9f0..8c9df2d 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -2345,9 +2345,8 @@
 {
 	const bool is_disconnected = chg_state_is_disconnected(&batt_drv->chg_state);
 	const struct gbms_chg_profile *profile = &batt_drv->chg_profile;
-	const int cc_max = GBMS_CCCM_LIMITS(profile, batt_drv->temp_idx, batt_drv->vbatt_idx);
 	const int soc = ssoc_get_capacity(&batt_drv->ssoc_state);
-	int vbatt_idx, ibatt, chg_speed;
+	int cc_max, vbatt_idx, ibatt, chg_speed;
 
 	if (is_disconnected)
 		return -1;
@@ -2368,6 +2367,7 @@
 		return -1;
 
 	/* slowing down due to batt_drv->temp_idx != from reference */
+	cc_max = GBMS_CCCM_LIMITS(profile, batt_drv->temp_idx, batt_drv->vbatt_idx);
 	if (cc_max && cc_max < batt_drv->nominal_demand)
 		batt_drv->nominal_demand = cc_max;