summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-11-15 13:36:33 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-16 16:40:22 +0000
commit41cf03de4c8c0cc1bf0297796893f925e8ee1cd8 (patch)
treed668ddcfc631641e70b1004b83b72cab07721b1d
parentd42bcfdb3b2da8041d4a648664be710c41412e53 (diff)
downloadchrome-ec-41cf03de4c8c0cc1bf0297796893f925e8ee1cd8.tar.gz
fuel_gauge: Simplify edge cases
Update the local static function to take the type in and use an assert since the bound checking is done at the call site. Also, improve the bounds checking to >= BATTERY_TYPE_COUNT. BRANCH=none BUG=none TEST=twister Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Ia79bdaafdcd6c48d29d8cef5f981f746066d35b5 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4030056 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r--common/battery_fuel_gauge.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/common/battery_fuel_gauge.c b/common/battery_fuel_gauge.c
index 88f941f194..e6aca68472 100644
--- a/common/battery_fuel_gauge.c
+++ b/common/battery_fuel_gauge.c
@@ -237,17 +237,12 @@ enum ec_error_list battery_sleep_fuel_gauge(void)
return sb_write(sleep_command->reg_addr, sleep_command->reg_data);
}
-static enum ec_error_list battery_get_fet_status_regval(int *regval)
+static enum ec_error_list battery_get_fet_status_regval(int type, int *regval)
{
int rv;
uint8_t data[6];
- int type = get_battery_type();
- /* If battery type is not known, can't check CHG/DCHG FETs */
- if (type == BATTERY_TYPE_COUNT) {
- /* Still don't know, so return here */
- return EC_ERROR_BUSY;
- }
+ ASSERT(type < BATTERY_TYPE_COUNT);
/* Read the status of charge/discharge FETs */
if (board_battery_info[type].fuel_gauge.fet.mfgacc_support == 1) {
@@ -270,7 +265,7 @@ int battery_is_charge_fet_disabled(void)
int type = get_battery_type();
/* If battery type is not known, can't check CHG/DCHG FETs */
- if (type == BATTERY_TYPE_COUNT) {
+ if (type >= BATTERY_TYPE_COUNT) {
/* Still don't know, so return here */
return -1;
}
@@ -281,7 +276,7 @@ int battery_is_charge_fet_disabled(void)
if (!board_battery_info[type].fuel_gauge.fet.cfet_mask)
return 0;
- rv = battery_get_fet_status_regval(&reg);
+ rv = battery_get_fet_status_regval(type, &reg);
if (rv)
return -1;
@@ -307,12 +302,12 @@ enum battery_disconnect_state battery_get_disconnect_state(void)
int type = get_battery_type();
/* If battery type is not known, can't check CHG/DCHG FETs */
- if (type == BATTERY_TYPE_COUNT) {
+ if (type >= BATTERY_TYPE_COUNT) {
/* Still don't know, so return here */
return BATTERY_DISCONNECT_ERROR;
}
- if (battery_get_fet_status_regval(&reg))
+ if (battery_get_fet_status_regval(type, &reg))
return BATTERY_DISCONNECT_ERROR;
if ((reg & board_battery_info[type].fuel_gauge.fet.reg_mask) ==