lkml.org 
[lkml]   [2020]   [Mar]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] sched/vtime: Fix an unitialized variable warning
Hi dude,

right before I was going to send the trivial, shut-up-gcc variant, I
thought that maybe we should do this instead.

Thoughts?

---
Fix:

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]
1007 | u64 val;
| ^~~

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

Signed-off-by: Borislav Petkov <bp@suse.de>
---
kernel/sched/cputime.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index dac9104d126f..ff9435dee1df 100644
--- a/kernel/sched/cputime.c
+++ b/kernel/sched/cputime.c
@@ -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);

--
2.21.0
--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette

\
 
 \ /
  Last update: 2020-03-27 22:45    [W:0.087 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site