From f21fbdb02e506643df255c7ccbe3dbedb725ad27 Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Sat, 4 Mar 2017 01:41:58 +0100 Subject: [PATCH] power: Keep boostpulse fd opened No one else should be writing to this, so keep the fd opened. Change-Id: I4258f7f7d69250f4832a67807031ab3faa9ff586 --- power/power.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/power/power.c b/power/power.c index 35946db..12b3440 100644 --- a/power/power.c +++ b/power/power.c @@ -62,7 +62,6 @@ enum power_profile_e { }; static enum power_profile_e current_power_profile = PROFILE_BALANCED; -static bool boostpulse_warned = false; /********************************************************** *** HELPER FUNCTIONS @@ -140,29 +139,32 @@ static void boost(int32_t duration_us) close(fd); } -/********************************************************** - *** POWER FUNCTIONS - **********************************************************/ +static void boostpulse_open(struct samsung_power_module *samsung_pwr) +{ + samsung_pwr->boostpulse_fd = open(BOOSTPULSE_PATH, O_WRONLY); + if (samsung_pwr->boostpulse_fd < 0) { + ALOGE("Error opening %s: %s\n", BOOSTPULSE_PATH, strerror(errno)); + } +} -/* You need to request the powerhal lock before calling this function */ -static int boostpulse_open(struct samsung_power_module *samsung_pwr) +static void send_boostpulse(int boostpulse_fd) { - char errno_str[64]; + int len; - if (samsung_pwr->boostpulse_fd < 0) { - samsung_pwr->boostpulse_fd = open(BOOSTPULSE_PATH, O_WRONLY); - if (samsung_pwr->boostpulse_fd < 0) { - if (!boostpulse_warned) { - strerror_r(errno, errno_str, sizeof(errno_str)); - ALOGE("Error opening %s: %s", BOOSTPULSE_PATH, errno_str); - boostpulse_warned = true; - } - } + if (boostpulse_fd < 0) { + return; } - return samsung_pwr->boostpulse_fd; + len = write(boostpulse_fd, "1", 1); + if (len < 0) { + ALOGE("Error writing to %s: %s", BOOSTPULSE_PATH, strerror(errno)); + } } +/********************************************************** + *** POWER FUNCTIONS + **********************************************************/ + static void set_power_profile(struct samsung_power_module *samsung_pwr, int profile) { @@ -413,16 +415,7 @@ static void samsung_power_hint(struct power_module *module, } ALOGV("%s: POWER_HINT_INTERACTION", __func__); - - if (boostpulse_open(samsung_pwr) >= 0) { - len = write(samsung_pwr->boostpulse_fd, "1", 1); - - if (len < 0) { - strerror_r(errno, errno_str, sizeof(errno_str)); - ALOGE("Error writing to %s: %s", BOOSTPULSE_PATH, errno_str); - } - } - + send_boostpulse(samsung_pwr->boostpulse_fd); break; } case POWER_HINT_VSYNC: { -- 2.20.1