power: fix sysfs_read/sysfs_write usage
* The incoming path to sysfs_read/sysfs_write should be const, as in
open(2) call.
* Redefine scaling_gov_path as const pointer array.
* Since sysfs_read works on a simple absolute path anyway, make sure
the scaling_gov_path paths *are* absolute. Otherwise the code only
works if Power HAL has / as CWD, which is a bit fragile.
Change-Id: I70c08f8137842569514bcb3f6e0617d46044e6ab
Signed-off-by: Corinna Vinschen <xda@vinschen.de>
diff --git a/utils.c b/utils.c
index 409fcb1..e79c587 100644
--- a/utils.c
+++ b/utils.c
@@ -46,10 +46,10 @@
#define SOC_ID_0 "/sys/devices/soc0/soc_id"
#define SOC_ID_1 "/sys/devices/system/soc/soc0/id"
-char scaling_gov_path[4][80] = {"sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
- "sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
+const char* scaling_gov_path[4] = {"/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor",
+ "/sys/devices/system/cpu/cpu1/cpufreq/scaling_governor",
+ "/sys/devices/system/cpu/cpu2/cpufreq/scaling_governor",
+ "/sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"};
#define PERF_HAL_PATH "libqti-perfd-client.so"
static void* qcopt_handle;
@@ -114,7 +114,7 @@
}
}
-int sysfs_read(char* path, char* s, int num_bytes) {
+int sysfs_read(const char* path, char* s, int num_bytes) {
char buf[80];
int count;
int ret = 0;
@@ -141,7 +141,7 @@
return ret;
}
-int sysfs_write(char* path, char* s) {
+int sysfs_write(const char* path, char* s) {
char buf[80];
int len;
int ret = 0;
diff --git a/utils.h b/utils.h
index 7d6f84b..429e9cd 100644
--- a/utils.h
+++ b/utils.h
@@ -33,8 +33,8 @@
char value[PROP_VALUE_MAX];
} PropVal;
-int sysfs_read(char* path, char* s, int num_bytes);
-int sysfs_write(char* path, char* s);
+int sysfs_read(const char* path, char* s, int num_bytes);
+int sysfs_write(const char* path, char* s);
int get_scaling_governor(char governor[], int size);
int get_scaling_governor_check_cores(char governor[], int size, int core_num);
int is_interactive_governor(char*);