thermal: fix to read and parse the contents of the sysfs
authortaeyoung <ty317.kim@samsung.com>
Wed, 23 Nov 2016 08:20:37 +0000 (17:20 +0900)
committertaeyoung <ty317.kim@samsung.com>
Wed, 23 Nov 2016 08:20:37 +0000 (17:20 +0900)
Change-Id: Ic884fb7d48bc64dc02d9e009fb5887a5c8aa9905
Signed-off-by: taeyoung <ty317.kim@samsung.com>
hw/thermal/thermal.c

index bdb47c8..9301044 100644 (file)
@@ -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;