diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-09-14 10:47:53 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-09-20 21:29:59 -0700 |
commit | 69246cf51011ca951e5c405f5a4d2ee4448eb66c (patch) | |
tree | d99ec6c42874d825f705bcd3ba3c7a709c103232 /common/charge_manager.c | |
parent | d5b9b8c12570a57def102d0039f0aef379582fb0 (diff) | |
download | chrome-ec-69246cf51011ca951e5c405f5a4d2ee4448eb66c.tar.gz |
chgmgr: Allow charge_manager_update_charge to accept NULL
Currently, charge_manager_update_charge does not handle NULL pointer
for struct charge_port_info any differently. It's not sanity-checked
either (thus memory access violation can occur).
This patch will make charge_manager_update_charge accept NULL pointer
and set available current and voltage to zero.
This also helps callers' intentions be clear because callers can
explicitly specify NULL (instead of passing a pointer to chg = {0},
which is initialized somewhere else).
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=none
BRANCH=none
TEST=buildall
Change-Id: I518662ab6a3a07f93da5d34cf62a6f856884f67d
Reviewed-on: https://chromium-review.googlesource.com/1226125
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Diffstat (limited to 'common/charge_manager.c')
-rw-r--r-- | common/charge_manager.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c index 08bd3d1b0a..c7620a69dc 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -910,6 +910,9 @@ void charge_manager_update_charge(int supplier, int port, const struct charge_port_info *charge) { + struct charge_port_info zero = {0}; + if (!charge) + charge = &zero; charge_manager_make_change(CHANGE_CHARGE, supplier, port, charge); } |