From 788606cb8864765bb16be23d368725df84d0e3cc Mon Sep 17 00:00:00 2001 From: Andrey Utkin Date: Sat, 19 Jul 2014 22:14:04 +0300 Subject: PM / tools: cpupower: drop negativity check on unsigned value Link: https://bugzilla.kernel.org/show_bug.cgi?id=80621 Reported-by: David Binderman Signed-off-by: Andrey Utkin Signed-off-by: Rafael J. Wysocki diff --git a/tools/power/cpupower/utils/helpers/sysfs.c b/tools/power/cpupower/utils/helpers/sysfs.c index 851c7a1..09afe5d 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) close(fd); value = strtoull(linebuf, &endp, 0); - if (value > 1 || value < 0) + if (value > 1) return -EINVAL; return value; -- cgit v0.10.2 From 103f1790715e9a45f069ae1028331be0be1e3bce Mon Sep 17 00:00:00 2001 From: Thomas Renninger Date: Tue, 22 Jul 2014 16:06:01 +0200 Subject: cpupower: Adjust MAINTAINERS file Dominik seems to not respond to emails any more since he finished studies. Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki diff --git a/MAINTAINERS b/MAINTAINERS index e31c874..76a1b0f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2522,8 +2522,8 @@ F: arch/x86/kernel/cpuid.c F: arch/x86/kernel/msr.c CPU POWER MONITORING SUBSYSTEM -M: Dominik Brodowski M: Thomas Renninger +L: linux-pm@vger.kernel.org S: Maintained F: tools/power/cpupower/ -- cgit v0.10.2 From 97fa1c5ca680bdee2c650e3aadf2a839b92f3f0e Mon Sep 17 00:00:00 2001 From: Himangi Saraogi Date: Tue, 29 Jul 2014 18:12:18 +0200 Subject: cpupower: mperf monitor: Correct use of ! and & In commit ae91d60ba88ef0bdb1b5e9b2363bd52fc45d2af7, a bug was fixed that involved converting !x & y to !(x & y). The code below shows the same pattern, and thus should perhaps be fixed in the same way. The Coccinelle semantic patch that makes this change is as follows: // @@ expression E1,E2; @@ ( !E1 & !E2 | - !E1 & E2 + !(E1 & E2) ) // Signed-off-by: Himangi Saraogi Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki diff --git a/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c b/tools/power/cpupower/utils/idle_monitor/mperf_monitor.c index 5650ab5..90a8c4f 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) unsigned long long hwcr; unsigned long min; - if (!cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC) + if (!(cpupower_cpu_info.caps & CPUPOWER_CAP_INV_TSC)) goto use_sysfs; if (cpupower_cpu_info.vendor == X86_VENDOR_AMD) { -- cgit v0.10.2 From 13f6de52b149c030b0d529a3d8d68267ed20f01c Mon Sep 17 00:00:00 2001 From: Rickard Strandqvist Date: Tue, 29 Jul 2014 18:12:19 +0200 Subject: cpupower: bench: parse.c: Fix several minor errors Resolved several minor errors in prepare_config() and made some additional improvements. Earlier, the risk of file stream that was not closed. Misuse of strncpy, and the use of strncmp with strlen that makes it pointless. I also check that sscanf has been successful, otherwise continue to the next line. And minimized the use of magic numbers. This was found using a static code analysis program called cppcheck. Signed-off-by: Rickard Strandqvist Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c index 543bba1..f503fb5 100644 --- a/tools/power/cpupower/bench/parse.c +++ b/tools/power/cpupower/bench/parse.c @@ -158,14 +158,15 @@ struct config *prepare_default_config() int prepare_config(const char *path, struct config *config) { size_t len = 0; - char *opt, *val, *line = NULL; - FILE *configfile = fopen(path, "r"); + char opt[16], val[32], *line = NULL; + FILE *configfile; if (config == NULL) { fprintf(stderr, "error: config is NULL\n"); return 1; } + configfile = fopen(path, "r"); if (configfile == NULL) { perror("fopen"); fprintf(stderr, "error: unable to read configfile\n"); @@ -174,52 +175,54 @@ int prepare_config(const char *path, struct config *config) } while (getline(&line, &len, configfile) != -1) { - if (line[0] == '#' || line[0] == ' ') + if (line[0] == '#' || line[0] == ' ' || line[0] == '\n') continue; - sscanf(line, "%as = %as", &opt, &val); + if (sscanf(line, "%14s = %30s", opt, val) < 2) + continue; dprintf("parsing: %s -> %s\n", opt, val); - if (strncmp("sleep", opt, strlen(opt)) == 0) + if (strcmp("sleep", opt) == 0) sscanf(val, "%li", &config->sleep); - else if (strncmp("load", opt, strlen(opt)) == 0) + else if (strcmp("load", opt) == 0) sscanf(val, "%li", &config->load); - else if (strncmp("load_step", opt, strlen(opt)) == 0) + else if (strcmp("load_step", opt) == 0) sscanf(val, "%li", &config->load_step); - else if (strncmp("sleep_step", opt, strlen(opt)) == 0) + else if (strcmp("sleep_step", opt) == 0) sscanf(val, "%li", &config->sleep_step); - else if (strncmp("cycles", opt, strlen(opt)) == 0) + else if (strcmp("cycles", opt) == 0) sscanf(val, "%u", &config->cycles); - else if (strncmp("rounds", opt, strlen(opt)) == 0) + else if (strcmp("rounds", opt) == 0) sscanf(val, "%u", &config->rounds); - else if (strncmp("verbose", opt, strlen(opt)) == 0) + else if (strcmp("verbose", opt) == 0) sscanf(val, "%u", &config->verbose); - else if (strncmp("output", opt, strlen(opt)) == 0) + else if (strcmp("output", opt) == 0) config->output = prepare_output(val); - else if (strncmp("cpu", opt, strlen(opt)) == 0) + else if (strcmp("cpu", opt) == 0) sscanf(val, "%u", &config->cpu); - else if (strncmp("governor", opt, 14) == 0) - strncpy(config->governor, val, 14); + else if (strcmp("governor", opt) == 0) { + strncpy(config->governor, val, + sizeof(config->governor)); + config->governor[sizeof(config->governor) - 1] = '\0'; + } - else if (strncmp("priority", opt, strlen(opt)) == 0) { + else if (strcmp("priority", opt) == 0) { if (string_to_prio(val) != SCHED_ERR) config->prio = string_to_prio(val); } } free(line); - free(opt); - free(val); return 0; } -- cgit v0.10.2 From 059802f961db9717412b6958111ca1cd1865726e Mon Sep 17 00:00:00 2001 From: Peter Senna Tschudin Date: Tue, 29 Jul 2014 18:12:20 +0200 Subject: cpupower: Remove redundant error check Remove double checks, and move the call to print_error to the first check. Replace break by return, and return 0 on success. The simplified version of the coccinelle semantic patch that fixes this issue is as follows: // @@ expression E; identifier pr; expression list es; @@ for(...;...;...){ ... - if (E) break; + if (E){ + pr(es); + break; + } ... } - if(E) pr(es); // Signed-off-by: Peter Senna Tschudin Signed-off-by: Thomas Renninger Signed-off-by: Rafael J. Wysocki diff --git a/tools/power/cpupower/utils/cpufreq-set.c b/tools/power/cpupower/utils/cpufreq-set.c index a416de8..f656e58 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) printf(_("Setting cpu: %d\n"), cpu); ret = do_one_cpu(cpu, &new_pol, freq, policychange); - if (ret) - break; + if (ret) { + print_error(); + return ret; + } } - if (ret) - print_error(); - - return ret; + return 0; } -- cgit v0.10.2