From 9a2ed2843c9ebe457cec286a63ef826b977242bb Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 23 Sep 2020 14:00:50 +0900 Subject: [PATCH] Fix check_async_call_rate() This is to prevent a broken pair of lock/release by check_async_call_rate() Do not invoke device_power_release_lock(type) unless the type is locked. Change-Id: I4cb8517fd5abce72ba0b9c405434706f64db10b9 Signed-off-by: Hyotaek Shim --- src/power.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/power.c b/src/power.c index feb9431..2d4762c 100644 --- a/src/power.c +++ b/src/power.c @@ -86,6 +86,9 @@ static struct _lock_timeout { .release = LOCK_CPU_TIMEOUT_MAX, .padding = LOCK_CPU_PADDING_TIMEOUT, }; +static bool power_locked_CPU; +static bool power_locked_DISPLAY; +static bool power_locked_DISPLAY_DIM; static char *get_state_str(display_state_e state) { @@ -455,10 +458,15 @@ int device_power_request_lock(power_lock_e type, int timeout_ms) if (ret == 0 && (timeout_ms == 0 || timeout_ms > lock_timeout.release)) add_off_lock_timeout(); - } else if (type == POWER_LOCK_DISPLAY) + power_locked_CPU = true; + } else if (type == POWER_LOCK_DISPLAY) { ret = lock_state(DISPLAY_STATE_NORMAL, STAY_CUR_STATE, timeout_ms); - else if (type == POWER_LOCK_DISPLAY_DIM) + power_locked_DISPLAY = true; + } + else if (type == POWER_LOCK_DISPLAY_DIM) { ret = lock_state(DISPLAY_STATE_SCREEN_DIM, STAY_CUR_STATE, timeout_ms); + power_locked_DISPLAY_DIM = true; + } else return DEVICE_ERROR_INVALID_PARAMETER; @@ -471,24 +479,21 @@ int device_power_release_lock(power_lock_e type) _I("power_lock_e = %d", type); - if (check_async_call_rate() < 0) { -//LCOV_EXCL_START System Error - _E("Rejected by too frequent calls; %d (calls per sec.) limit is violated." - , CHECK_RATE_THRESHOLD); - return DEVICE_ERROR_OPERATION_FAILED; -//LCOV_EXCL_STOP - } - - if (type == POWER_LOCK_CPU) { + if (type == POWER_LOCK_CPU && power_locked_CPU) { ret = unlock_state(DISPLAY_STATE_SCREEN_OFF, PM_SLEEP_MARGIN); if (ret == 0) { remove_off_lock_timeout(); remove_padding_timeout(); + power_locked_CPU = false; } - } else if (type == POWER_LOCK_DISPLAY) + } else if (type == POWER_LOCK_DISPLAY && power_locked_DISPLAY) { ret = unlock_state(DISPLAY_STATE_NORMAL, PM_KEEP_TIMER); - else if (type == POWER_LOCK_DISPLAY_DIM) + if (ret == 0) power_locked_DISPLAY = false; + } + else if (type == POWER_LOCK_DISPLAY_DIM && power_locked_DISPLAY_DIM) { ret = unlock_state(DISPLAY_STATE_SCREEN_DIM, PM_KEEP_TIMER); + if (ret == 0) power_locked_DISPLAY_DIM = false; + } else return DEVICE_ERROR_INVALID_PARAMETER; -- 2.7.4