Change-Id: I770dc6986b618236372ce72f823a65ff64bf2f5c
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <hal/hal-power-interface.h>
#include <hal/hal-power-interface.h>
static int bus_dvfs_get_curr_freq(char *res_name)
{
char buf[BUFF_MAX + 1];
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;
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;
+#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);
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]);
}
return (ret < 0) ? ret : (gpu_freq_table[freq]);
}
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/max_freq", &freq);
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];
}
return (ret < 0) ? ret : gpu_freq_table[freq];
}
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/cur_freq", &freq);
int freq, ret;
ret = sysfs_read_int("/sys/class/mpgpu/cur_freq", &freq);
- if (ret < 0)
- return ret;
return (ret < 0) ? ret : (freq * 1000);
}
return (ret < 0) ? ret : (freq * 1000);
}