summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongwoo Lee <dwoo08.lee@samsung.com>2022-08-25 20:07:29 +0900
committerDongwoo Lee <dwoo08.lee@samsung.com>2022-08-25 20:27:01 +0900
commitbc3949a563eb8575d9ad5eeffa68fea68ac944a2 (patch)
tree8a25bc8f9cfb647e79450379294d0b72dd98b01c
parent87962b8ddff7c4aa4fc6671fedf9d097042b78c8 (diff)
downloadpower-vim3-bc3949a563eb8575d9ad5eeffa68fea68ac944a2.tar.gz
power-vim3-bc3949a563eb8575d9ad5eeffa68fea68ac944a2.tar.bz2
power-vim3-bc3949a563eb8575d9ad5eeffa68fea68ac944a2.zip
Change-Id: I770dc6986b618236372ce72f823a65ff64bf2f5c Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
-rw-r--r--src/hal-backend-power.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/hal-backend-power.c b/src/hal-backend-power.c
index 2a9bd7f..8de87a6 100644
--- a/src/hal-backend-power.c
+++ b/src/hal-backend-power.c
@@ -20,7 +20,6 @@
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
#include <hal/hal-power-interface.h>
@@ -366,14 +365,17 @@ static struct pass_resource_tmu_ops tmu_ops = {
static int bus_dvfs_get_curr_freq(char *res_name)
{
char buf[BUFF_MAX + 1];
- char unit[BUFF_MAX + 1];
int ret, freq;
ret = sysfs_read_str("/sys/class/aml_ddr/freq", buf, BUFF_MAX);
if (ret < 0)
return ret;
- sscanf(buf, "%d %s", &freq, unit);
+ if (sscanf(buf, "%d %*s", &freq) != 1)
+ return -EINVAL;
+
+ if (freq < 0 || freq > INT_MAX/1000)
+ return -EINVAL;
return (freq * 1000);
}
@@ -386,13 +388,17 @@ static int gpu_freq_table[] = {
800000,
};
+#define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))
+
static int gpu_dvfs_get_min_freq(char *res_name)
{
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/min_freq", &freq);
- if (ret < 0)
- return ret;
+
+ if (freq < 0 || freq >= ARRAY_LENGTH(gpu_freq_table))
+ return -EINVAL;
+
return (ret < 0) ? ret : (gpu_freq_table[freq]);
}
@@ -401,8 +407,9 @@ static int gpu_dvfs_get_max_freq(char *res_name)
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/max_freq", &freq);
- if (ret < 0)
- return ret;
+ if (freq < 0 || freq >= ARRAY_LENGTH(gpu_freq_table))
+ return -EINVAL;
+
return (ret < 0) ? ret : gpu_freq_table[freq];
}
@@ -411,8 +418,7 @@ static int gpu_dvfs_get_curr_freq(char *res_name)
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/cur_freq", &freq);
- if (ret < 0)
- return ret;
+
return (ret < 0) ? ret : (freq * 1000);
}