diff options
author | Louis Yung-Chieh Lo <yjlou@chromium.org> | 2014-04-14 15:51:42 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-21 20:58:32 +0000 |
commit | 58878e79e07f33050d6ff8d280e5db63b5902e10 (patch) | |
tree | 05abf3306c786062bdf843c53c515f9cac0a2e2d /common/battery.c | |
parent | bd1a3ffeaf6d40d96b43c1169b150ae68a6d1291 (diff) | |
download | chrome-ec-58878e79e07f33050d6ff8d280e5db63b5902e10.tar.gz |
Fixed the stack overflow bug in 'battery' console command.stabilize-5784.0.B
On the Nyan EC, we almost run out of the stack of console task.
Instead of making that struct static or global, we print the cached data.
Read the issue tracker for more detailed discussion.
BUG=chrome-os-partner:28027
BRANCH=tot
TEST=verified on nyan with/without battery.
The "battery" console command doesn't crash the system.
Change-Id: Id5246724760aed4cf1df827baf115007b2ffb48e
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/194875
Reviewed-by: Dave Parker <dparker@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/battery.c')
-rw-r--r-- | common/battery.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/common/battery.c b/common/battery.c index 1f8b757929..25df2e17a3 100644 --- a/common/battery.c +++ b/common/battery.c @@ -6,6 +6,7 @@ */ #include "battery.h" +#include "charge_state.h" #include "common.h" #include "console.h" #include "gpio.h" @@ -96,41 +97,51 @@ static void print_battery_strings(void) static void print_battery_params(void) { - struct batt_params batt; +#if defined(HAS_TASK_CHARGER) + /* Ask charger so that we don't need to ask battery again. */ + const struct batt_params *batt = charger_current_battery_params(); +#else + /* This is for test code, where doesn't have charger task. */ + struct batt_params _batt; + const struct batt_params *batt = &_batt; + + battery_get_params(&_batt); +#endif - battery_get_params(&batt); print_item_name("Param flags:"); - ccprintf("%08x\n", batt.flags); + ccprintf("%08x\n", batt->flags); print_item_name("Temp:"); ccprintf("0x%04x = %.1d K (%.1d C)\n", - batt.temperature, batt.temperature, batt.temperature - 2731); + batt->temperature, + batt->temperature, + batt->temperature - 2731); print_item_name("V:"); - ccprintf("0x%04x = %d mV\n", batt.voltage, batt.voltage); + ccprintf("0x%04x = %d mV\n", batt->voltage, batt->voltage); print_item_name("V-desired:"); - ccprintf("0x%04x = %d mV\n", batt.desired_voltage, - batt.desired_voltage); + ccprintf("0x%04x = %d mV\n", batt->desired_voltage, + batt->desired_voltage); print_item_name("I:"); - ccprintf("0x%04x = %d mA", batt.current & 0xffff, batt.current); - if (batt.current > 0) + ccprintf("0x%04x = %d mA", batt->current & 0xffff, batt->current); + if (batt->current > 0) ccputs("(CHG)"); - else if (batt.current < 0) + else if (batt->current < 0) ccputs("(DISCHG)"); ccputs("\n"); print_item_name("I-desired:"); - ccprintf("0x%04x = %d mA\n", batt.desired_current, - batt.desired_current); + ccprintf("0x%04x = %d mA\n", batt->desired_current, + batt->desired_current); print_item_name("Charging:"); ccprintf("%sAllowed\n", - batt.flags & BATT_FLAG_WANT_CHARGE ? "" : "Not "); + batt->flags & BATT_FLAG_WANT_CHARGE ? "" : "Not "); print_item_name("Charge:"); - ccprintf("%d %%\n", batt.state_of_charge); + ccprintf("%d %%\n", batt->state_of_charge); } static void print_battery_info(void) |