From e143419bfff3f17fa10f2cc5f70a87f268cd1c48 Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Fri, 18 Nov 2016 18:56:17 +0100 Subject: [PATCH] power: Simplify read_panel_brightness() Overengineering. Change-Id: Ifef79a7e8f2249fdd22099a043303f9686ac014b --- power/power.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/power/power.c b/power/power.c index f28dce51..b33243bb 100644 --- a/power/power.c +++ b/power/power.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -124,11 +125,14 @@ static void sysfs_write(const char *path, char *s) close(fd); } -static unsigned int read_panel_brightness() { - unsigned int i, ret = 0; +static int read_panel_brightness() { + int ret = 0; int read_status; // brightness can range from 0 to 255, so max. 3 chars + '\0' char panel_brightness[4]; + // for strtol + char *dummy; + const int base = 10; read_status = sysfs_read(PANEL_BRIGHTNESS, panel_brightness, sizeof(PANEL_BRIGHTNESS)); if (read_status < 0) { @@ -136,12 +140,7 @@ static unsigned int read_panel_brightness() { return -1; } - for (i = 0; i < (sizeof(panel_brightness) / sizeof(panel_brightness[0])); i++) { - if (isdigit(panel_brightness[i])) { - ret += (panel_brightness[i] - '0'); - } - } - + ret = strtol(panel_brightness, &dummy, base); ALOGV("%s: Panel brightness is: %d", __func__, ret); return ret;