From 544ba7da11eeeae342861b5ecfc72a50152a4711 Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Buchillon Date: Wed, 23 Jan 2019 08:49:58 +0800 Subject: powerbtn/button: fix crash on 0ms sleep This change guards against crashing the EC when calling button or powerbtn with a 0 as the argument. BRANCH=None BUG=chromium:905829 TEST=manual testing on soraka > powerbtn 0 Simulating 0 ms power button press. Simulating power button release. > button vup 0 > Change-Id: I022c9e48b0977b71b8706e5ffe8356a226a59077 Signed-off-by: Ruben Rodriguez Buchillon Reviewed-on: https://chromium-review.googlesource.com/1428500 Commit-Ready: ChromeOS CL Exonerator Bot Reviewed-by: Hung-Te Lin Reviewed-by: Yilun Lin Reviewed-by: Nicolas Boichat --- common/button.c | 3 ++- common/power_button.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/common/button.c b/common/button.c index 1ccc548c75..4ca1dac852 100644 --- a/common/button.c +++ b/common/button.c @@ -367,7 +367,8 @@ static int console_command_button(int argc, char **argv) button_interrupt_simulate(button_idx); /* Hold the button(s) */ - msleep(press_ms); + if (press_ms > 0) + msleep(press_ms); /* Release the button(s) */ for (button_idx = 0; button_idx < BUTTON_COUNT; button_idx++) diff --git a/common/power_button.c b/common/power_button.c index a5da582afd..97ac7b0a77 100644 --- a/common/power_button.c +++ b/common/power_button.c @@ -179,7 +179,8 @@ static int command_powerbtn(int argc, char **argv) power_button_is_stable = 0; hook_call_deferred(&power_button_change_deferred_data, 0); - msleep(ms); + if (ms > 0) + msleep(ms); ccprintf("Simulating power button release.\n"); simulate_power_pressed = 0; -- cgit v1.2.1