sched/vtime: Work around an unitialized variable warning
authorBorislav Petkov <bp@suse.de>
Fri, 27 Mar 2020 21:43:34 +0000 (22:43 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 15 Apr 2020 09:06:50 +0000 (11:06 +0200)
Work around this warning:

  kernel/sched/cputime.c: In function ‘kcpustat_field’:
  kernel/sched/cputime.c:1007:6: warning: ‘val’ may be used uninitialized in this function [-Wmaybe-uninitialized]

because GCC can't see that val is used only when err is 0.

Acked-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20200327214334.GF8015@zn.tnic
kernel/sched/cputime.c

index dac9104d126f7d4483a64a46c965bb48fcbdc811..ff9435dee1df218a96d05ac4fc1130f0bca204e1 100644 (file)
@@ -1003,12 +1003,12 @@ u64 kcpustat_field(struct kernel_cpustat *kcpustat,
                   enum cpu_usage_stat usage, int cpu)
 {
        u64 *cpustat = kcpustat->cpustat;
+       u64 val = cpustat[usage];
        struct rq *rq;
-       u64 val;
        int err;
 
        if (!vtime_accounting_enabled_cpu(cpu))
-               return cpustat[usage];
+               return val;
 
        rq = cpu_rq(cpu);