aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/power/cpupower/bench/parse.c39
-rw-r--r--tools/power/cpupower/utils/cpufreq-set.c11
-rw-r--r--tools/power/cpupower/utils/helpers/sysfs.c2
-rw-r--r--tools/power/cpupower/utils/idle_monitor/mperf_monitor.c2
4 files changed, 28 insertions, 26 deletions
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index 543bba14ae2c..f503fb53824e 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -158,14 +158,15 @@ struct config *prepare_default_config()
158int prepare_config(const char *path, struct config *config) 158int prepare_config(const char *path, struct config *config)
159{ 159{
160 size_t len = 0; 160 size_t len = 0;
161 char *opt, *val, *line = NULL; 161 char opt[16], val[32], *line = NULL;
162 FILE *configfile = fopen(path, "r"); 162 FILE *configfile;
163 163
164 if (config == NULL) { 164 if (config == NULL) {
165 fprintf(stderr, "error: config is NULL\n"); 165 fprintf(stderr, "error: config is NULL\n");
166 return 1; 166 return 1;
167 } 167 }
168 168
169 configfile = fopen(path, "r");
169 if (configfile == NULL) { 170 if (configfile == NULL) {
170 perror("fopen"); 171 perror("fopen");
171 fprintf(stderr, "error: unable to read configfile\n"); 172 fprintf(stderr, "error: unable to read configfile\n");
@@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config)
174 } 175 }
175 176
176 while (getline(&line, &len, configfile) != -1) { 177 while (getline(&line, &len, configfile) != -1) {
177 if (line[0] == '#' || line[0] == ' ') 178 if (line[0] == '#' || line[0] == ' ' || line[0] == '\n')
178 continue; 179 continue;
179 180
180 sscanf(line, "%as = %as", &opt, &val); 181 if (sscanf(line, "%14s = %30s", opt, val) < 2)
182 continue;
181 183
182 dprintf("parsing: %s -> %s\n", opt, val); 184 dprintf("parsing: %s -> %s\n", opt, val);
183 185
184 if (strncmp("sleep", opt, strlen(opt)) == 0) 186 if (strcmp("sleep", opt) == 0)
185 sscanf(val, "%li", &config->sleep); 187 sscanf(val, "%li", &config->sleep);
186 188
187 else if (strncmp("load", opt, strlen(opt)) == 0) 189 else if (strcmp("load", opt) == 0)
188 sscanf(val, "%li", &config->load); 190 sscanf(val, "%li", &config->load);
189 191
190 else if (strncmp("load_step", opt, strlen(opt)) == 0) 192 else if (strcmp("load_step", opt) == 0)
191 sscanf(val, "%li", &config->load_step); 193 sscanf(val, "%li", &config->load_step);
192 194
193 else if (strncmp("sleep_step", opt, strlen(opt)) == 0) 195 else if (strcmp("sleep_step", opt) == 0)
194 sscanf(val, "%li", &config->sleep_step); 196 sscanf(val, "%li", &config->sleep_step);
195 197
196 else if (strncmp("cycles", opt, strlen(opt)) == 0) 198 else if (strcmp("cycles", opt) == 0)
197 sscanf(val, "%u", &config->cycles); 199 sscanf(val, "%u", &config->cycles);
198 200
199 else if (strncmp("rounds", opt, strlen(opt)) == 0) 201 else if (strcmp("rounds", opt) == 0)
200 sscanf(val, "%u", &config->rounds); 202 sscanf(val, "%u", &config->rounds);
201 203
202 else if (strncmp("verbose", opt, strlen(opt)) == 0) 204 else if (strcmp("verbose", opt) == 0)
203 sscanf(val, "%u", &config->verbose); 205 sscanf(val, "%u", &config->verbose);
204 206
205 else if (strncmp("output", opt, strlen(opt)) == 0) 207 else if (strcmp("output", opt) == 0)
206 config->output = prepare_output(val); 208 config->output = prepare_output(val);
207 209
208 else if (strncmp("cpu", opt, strlen(opt)) == 0) 210 else if (strcmp("cpu", opt) == 0)
209 sscanf(val, "%u", &config->cpu); 211 sscanf(val, "%u", &config->cpu);
210 212
211 else if (strncmp("governor", opt, 14) == 0) 213 else if (strcmp("governor", opt) == 0) {
212 strncpy(config->governor, val, 14); 214 strncpy(config->governor, val,
215 sizeof(config->governor));
216 config->governor[sizeof(config->governor) - 1] = '\0';
217 }
213 218
214 else if (strncmp("priority", opt, strlen(opt)) == 0) { 219 else if (strcmp("priority", opt) == 0) {
215 if (string_to_prio(val) != SCHED_ERR) 220 if (string_to_prio(val) != SCHED_ERR)
216 config->prio = string_to_prio(val); 221 config->prio = string_to_prio(val);
217 } 222 }
218 } 223 }
219 224
220 free(line); 225 free(line);
221 free(opt);
222 free(val);
223 226
224 return 0; 227 return 0;
225} 228}
diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c
index a416de80c55e..f656e585ed45 100644
--- a/tools/power/cpupower/utils/cpufreq-set.c
+++ b/tools/power/cpupower/utils/cpufreq-set.c
@@ -320,12 +320,11 @@ int cmd_freq_set(int argc, char **argv)
320 320
321 printf(_("Setting cpu: %d\n"), cpu); 321 printf(_("Setting cpu: %d\n"), cpu);
322 ret = do_one_cpu(cpu, &new_pol, freq, policychange); 322 ret = do_one_cpu(cpu, &new_pol, freq, policychange);
323 if (ret) 323 if (ret) {
324 break; 324 print_error();
325 return ret;
326 }
325 } 327 }
326 328
327 if (ret) 329 return 0;
328 print_error();
329
330 return ret;
331} 330}
diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c
index 851c7a16ca49..09afe5d87f2b 100644
--- a/tools/power/cpupower/utils/helpers/sysfs.c
+++ b/tools/power/cpupower/utils/helpers/sysfs.c
@@ -81,7 +81,7 @@ int sysfs_is_cpu_online(unsigned int cpu)
81 close(fd); 81 close(fd);
82 82
83 value = strtoull(linebuf, &endp, 0); 83 value = strtoull(linebuf, &endp, 0);
84 if (value > 1 || value < 0) 84 if (value > 1)
85 return -EINVAL; 85 return -EINVAL;
86 86
87 return value; 87 return value;
diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
index 5650ab5a2c20..90a8c4f071e7 100644
--- a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
+++ b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c
@@ -237,7 +237,7 @@ static int init_maxfreq_mode(void)
237 unsigned long long hwcr; 237 unsigned long long hwcr;
238 unsigned long min; 238 unsigned long min;
239 239
240 if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC) 240 if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC))
241 goto use_sysfs; 241 goto use_sysfs;
242 242
243 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { 243 if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) {