sched/vtime: Fix an unitialized variable warning
PATCH 1/1 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.
--- kernel/sched/cputime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cputime.c +2 -2
@@ -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);
Signature · 7 lines
2.21.0
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquettePeter Zijlstra
maintainerQuoted 31 lines · Borislav Petkov
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 <[email protected]>--- kernel/sched/cputime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)kernel/sched/cputime.c +0
-0@@ -1003,12 +1003,12 @@ u64 kcpustat_field(struct kernel_cpustat *kcpustat, enum cpu_usage_stat usage, int cpu) {u64 *cpustat = kcpustat->cpustat;
kernel/sched/cputime.c u64 kcpustat_field(struct kernel_cpustat *kcpustat, · line 1013
Quoted 10 lines
kernel/sched/cputime.c +2
-2+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);
Hurph.. this might result in an unconditional load (and extra cache-miss) for the vtime_accounting_enabled_cpu() case.
I suspesct the =0 this would be better. Stupid stupid compiler!
[tip: sched/urgent] sched/vtime: Work around an unitialized variable warning
In reply to Borislav PetkovThe following commit has been merged into the sched/urgent branch of tip:
The following commit has been merged into the sched/urgent branch of tip:
Commit-ID: e0d648f9d883ec1efab261af158d73aa30e9dd12 Gitweb: https://git.kernel.org/tip/e0d648f9d883ec1efab261af158d73aa30e9dd12 Author: Borislav Petkov <[email protected]> AuthorDate: Fri, 27 Mar 2020 22:43:34 +01:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 15 Apr 2020 11:06:50 +02:00
sched/vtime: Work around an unitialized variable warning
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.
--- kernel/sched/cputime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cputime.c +2 -2
@@ -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);