From 02869bb132b5f37f3cdb66eb4f85bbae5e4c774f Mon Sep 17 00:00:00 2001 From: taeyoung Date: Wed, 23 Nov 2016 17:20:37 +0900 Subject: [PATCH] thermal: fix to read and parse the contents of the sysfs Change-Id: Ic884fb7d48bc64dc02d9e009fb5887a5c8aa9905 Signed-off-by: taeyoung --- hw/thermal/thermal.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/hw/thermal/thermal.c b/hw/thermal/thermal.c index bdb47c8..9301044 100644 --- a/hw/thermal/thermal.c +++ b/hw/thermal/thermal.c @@ -38,16 +38,36 @@ static guint timer; static int thermal_get_state(struct thermal_info *info) { int ret, value; + FILE *fp; + char buf[32]; + size_t len; if (!info) return -EINVAL; - ret = sys_get_int(THERMAL_PATH, &value); - if (ret < 0) { - _E("Failed to read %s (%d)", THERMAL_PATH, ret); - return ret; + fp = fopen(THERMAL_PATH, "r"); + if (!fp) { + _E("Failed to open %s(%d)", THERMAL_PATH, errno); + return -errno; + } + + len = fread(buf, 1, sizeof(buf) - 1, fp); + fclose(fp); + if (len == 0) { + _E("Failed to read %s(%d)", THERMAL_PATH, errno); + return -errno; + } + buf[len] = '\0'; + + if (!strstr(buf, "temp:")) { + _E("Invalid temparature value (%s)", buf); + return -EINVAL; } + value = atoi(buf + 5); /* 5 == strlen("temp:") */ + + _I("AP temparature(%d)", value); + if (value < 30) { info->state = THERMAL_STATE_LOW; info->level = THERMAL_LEVEL_NORMAL; -- 2.7.4