cpupower: Remove redundant error check
authorPeter Senna Tschudin <peter.senna@gmail.com>
Tue, 29 Jul 2014 16:12:20 +0000 (18:12 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 29 Jul 2014 23:57:13 +0000 (01:57 +0200)
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:

// <smpl>
@@
expression E; identifier pr; expression list es;
@@
for(...;...;...){
...
- if (E) break;
+ if (E){
+ pr(es);
+ break;
+ }
...
}
- if(E) pr(es);
// </smpl>

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Signed-off-by: Thomas Renninger <trenn@suse.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
tools/power/cpupower/utils/cpufreq-set.c

index a416de80c55ea120f83b183b1b0db2aa824e2c22..f656e585ed45bae639744c09c735e80301f10ef2 100644 (file)
@@ -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;
 }