* [PATCH] sched/vtime: Fix an unitialized variable warning
@ 2020-03-27 21:43 Borislav Petkov
2020-03-30 14:35 ` Peter Zijlstra
2020-04-15 9:14 ` [tip: sched/urgent] sched/vtime: Work around " tip-bot2 for Borislav Petkov
0 siblings, 2 replies; 3+ messages in thread
From: Borislav Petkov @ 2020-03-27 21:43 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: x86-ml, lkml
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] sched/vtime: Fix an unitialized variable warning
2020-03-27 21:43 [PATCH] sched/vtime: Fix an unitialized variable warning Borislav Petkov
@ 2020-03-30 14:35 ` Peter Zijlstra
2020-04-15 9:14 ` [tip: sched/urgent] sched/vtime: Work around " tip-bot2 for Borislav Petkov
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2020-03-30 14:35 UTC (permalink / raw)
To: Borislav Petkov; +Cc: x86-ml, lkml
On Fri, Mar 27, 2020 at 10:43:34PM +0100, Borislav Petkov wrote:
> 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);
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!
^ permalink raw reply [flat|nested] 3+ messages in thread* [tip: sched/urgent] sched/vtime: Work around an unitialized variable warning
2020-03-27 21:43 [PATCH] sched/vtime: Fix an unitialized variable warning Borislav Petkov
2020-03-30 14:35 ` Peter Zijlstra
@ 2020-04-15 9:14 ` tip-bot2 for Borislav Petkov
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Borislav Petkov @ 2020-04-15 9:14 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Peter Zijlstra, Borislav Petkov, Ingo Molnar, x86, LKML
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 <bp@suse.de>
AuthorDate: Fri, 27 Mar 2020 22:43:34 +01:00
Committer: Ingo Molnar <mingo@kernel.org>
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.
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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c
index dac9104..ff9435d 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);
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-15 9:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-27 21:43 [PATCH] sched/vtime: Fix an unitialized variable warning Borislav Petkov
2020-03-30 14:35 ` Peter Zijlstra
2020-04-15 9:14 ` [tip: sched/urgent] sched/vtime: Work around " tip-bot2 for Borislav Petkov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox