google_battery: add boundary check for health state

Bug: 175072693
Signed-off-by: Jenny Ho <[email protected]>
Change-Id: Ie3552ccbec07332e28d50ef861e875eed76d6bad
Signed-off-by: Ken Tsou <[email protected]>
(cherry picked from commit 35964b20bd2fb92bafba7d11c76de2e108baa346)
diff --git a/google_battery.c b/google_battery.c
index c5278ea..264e192 100644
--- a/google_battery.c
+++ b/google_battery.c
@@ -4614,13 +4614,19 @@
 	batt_drv->fake_capacity = capacity;
 }
 
-static void gbatt_set_health(struct batt_drv *batt_drv, int health)
+static int gbatt_set_health(struct batt_drv *batt_drv, int health)
 {
+	if (health > POWER_SUPPLY_HEALTH_HOT ||
+	    health < POWER_SUPPLY_HEALTH_UNKNOWN)
+		return -EINVAL;
+
 	batt_drv->batt_health = health;
 
 	/* disable health charging if in overheat */
 	if (health == POWER_SUPPLY_HEALTH_OVERHEAT)
 		msc_logic_health(batt_drv);
+
+	return 0;
 }
 
 static int gbatt_get_property(struct power_supply *psy,
@@ -4841,8 +4847,8 @@
 	case POWER_SUPPLY_PROP_HEALTH:
 		mutex_lock(&batt_drv->chg_lock);
 		if (batt_drv->batt_health != val->intval) {
-			gbatt_set_health(batt_drv, val->intval);
-			if (batt_drv->psy)
+			ret = gbatt_set_health(batt_drv, val->intval);
+			if (ret == 0 && batt_drv->psy)
 				power_supply_changed(batt_drv->psy);
 		}
 		mutex_unlock(&batt_drv->chg_lock);