google_battery: initialize cycle counts for empty EEPROM

Bug: 228362133
Bug: 228392665
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: Iccc86df4289e8c8735329da9b12f4f678aa60d13
diff --git a/google_battery.c b/google_battery.c
index 5c3a196..d50e9f0 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -3822,7 +3822,7 @@
 /* call holding mutex_unlock(&ccd->lock); */
 static int batt_cycle_count_load(struct gbatt_ccbin_data *ccd)
 {
-	int ret;
+	int ret, i;
 
 	ret = gbms_storage_read(GBMS_TAG_BCNT, ccd->count, sizeof(ccd->count));
 	if (ret < 0 && ret != -ENOENT) {
@@ -3830,6 +3830,10 @@
 		return ret;
 	}
 
+	for (i = 0; i < GBMS_CCBIN_BUCKET_COUNT; i++)
+		if (ccd->count[i] == 0xFFFF)
+			ccd->count[i] = 0;
+
 	ccd->prev_soc = -1;
 	return 0;
 }