summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2020-02-14 15:14:14 +0800
committerCommit Bot <commit-bot@chromium.org>2020-02-17 09:46:36 +0000
commit7310e7c861d0c90640d9842cc0729a46357ff28f (patch)
tree49fbfea80094e19b795705c068ed7318a82b0ed3 /common/charge_state_v2.c
parentaa46cca7fc82e27ae25c4798c3547031a5567607 (diff)
downloadchrome-ec-7310e7c861d0c90640d9842cc0729a46357ff28f.tar.gz
charger_state: check BATT_FLAG_* flags before trusting the value
battery_get_params() did not ask drivers to set bad values to zero. And actually some driver did not initialize batt_params to zero. So the callee should be more careful when using the value. BUG=None TEST=On juniper, make sure `charge_request(some-buggy-value)` doesn't exist BRANCH=kukui Change-Id: I0d15f17c852f07e4ce5a4cd5cae4c25e84efea8a Signed-off-by: Ting Shen <phoenixshen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2056111 Reviewed-by: Jett Rink <jettrink@chromium.org> Tested-by: Devin Lu <Devin.Lu@quantatw.com> Tested-by: Ting Shen <phoenixshen@chromium.org> Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index cb225c7a3b..c5592cf5d1 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1754,8 +1754,14 @@ void charger_task(void *u)
* battery it uses (0, 0), which is probably safer than blindly
* applying power to a battery we can't talk to.
*/
- curr.requested_voltage = curr.batt.desired_voltage;
- curr.requested_current = curr.batt.desired_current;
+ if (curr.batt.flags & (BATT_FLAG_BAD_DESIRED_VOLTAGE |
+ BATT_FLAG_BAD_DESIRED_CURRENT)) {
+ curr.requested_voltage = 0;
+ curr.requested_current = 0;
+ } else {
+ curr.requested_voltage = curr.batt.desired_voltage;
+ curr.requested_current = curr.batt.desired_current;
+ }
/* If we *know* there's no battery, wait for one to appear. */
if (curr.batt.is_present == BP_NO) {