* [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning
@ 2021-11-07 9:01 Oliver Upton
2021-11-07 9:11 ` Oliver Upton
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Upton @ 2021-11-07 9:01 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Mark Rutland, Marc Zyngier, Daniel Lezcano, Nathan Chancellor,
Nick Desaulniers, clang-built-linux, Oliver Upton,
kernel test robot
Since commit 4775bc63f880 ("clocksource/arm_arch_timer: Add build-time
guards for unhandled register accesses"), clang builds emit the
following warning:
>> drivers/clocksource/arm_arch_timer.c:156:3: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
default:
^~~~~~~
drivers/clocksource/arm_arch_timer.c:163:9: note: uninitialized use occurs here
return val;
^~~
which is of course meaningless, as we break the build if the default
case is ever taken in the switch statement. Clang does static analysis
before deciding if the branch is ever taken, leading to the warning.
Fix the bogus warning by initializing val on the default branch.
Reported-by: kernel test robot <lkp@intel.com>
Fixes: 4775bc63f880 ("clocksource/arm_arch_timer: Add build-time guards for unhandled register accesses")
Signed-off-by: Oliver Upton <oupton@google.com>
---
Heh, I had caught this earlier but didn't hit send before starting the
weekend. Saw the bot email, so sending out.
drivers/clocksource/arm_arch_timer.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 9a04eacc4412..8e2814fcea11 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -172,6 +172,7 @@ u32 arch_timer_reg_read(int access, enum arch_timer_reg reg,
val = readl_relaxed(timer->base + CNTP_CTL);
break;
default:
+ val = 0;
BUILD_BUG();
}
} else if (access == ARCH_TIMER_MEM_VIRT_ACCESS) {
@@ -181,6 +182,7 @@ u32 arch_timer_reg_read(int access, enum arch_timer_reg reg,
val = readl_relaxed(timer->base + CNTV_CTL);
break;
default:
+ val = 0;
BUILD_BUG();
}
} else {
--
2.34.0.rc0.344.g81b53c2807-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning
2021-11-07 9:01 [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning Oliver Upton
@ 2021-11-07 9:11 ` Oliver Upton
2021-11-08 11:10 ` Miguel Ojeda
0 siblings, 1 reply; 3+ messages in thread
From: Oliver Upton @ 2021-11-07 9:11 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Mark Rutland, Marc Zyngier, Daniel Lezcano, Nathan Chancellor,
Nick Desaulniers, clang-built-linux, kernel test robot
On Sun, Nov 7, 2021 at 1:02 AM Oliver Upton <oupton@google.com> wrote:
>
> Since commit 4775bc63f880 ("clocksource/arm_arch_timer: Add build-time
> guards for unhandled register accesses"), clang builds emit the
> following warning:
>
> >> drivers/clocksource/arm_arch_timer.c:156:3: warning: variable 'val' is used uninitialized whenever switch default is taken [-Wsometimes-uninitialized]
> default:
> ^~~~~~~
> drivers/clocksource/arm_arch_timer.c:163:9: note: uninitialized use occurs here
> return val;
> ^~~
>
> which is of course meaningless, as we break the build if the default
> case is ever taken in the switch statement. Clang does static analysis
> before deciding if the branch is ever taken, leading to the warning.
>
> Fix the bogus warning by initializing val on the default branch.
>
> Reported-by: kernel test robot <lkp@intel.com>
> Fixes: 4775bc63f880 ("clocksource/arm_arch_timer: Add build-time guards for unhandled register accesses")
> Signed-off-by: Oliver Upton <oupton@google.com>
My inbox searching was poor, there is another thread on this issue
where Miguel proposed tweaking the assertion such that clang no longer
emits the warning. No longer having issues with the patch applied [1]
[1] http://lore.kernel.org/r/20211014132331.GA4811@kernel.org/
--
Oliver
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning
2021-11-07 9:11 ` Oliver Upton
@ 2021-11-08 11:10 ` Miguel Ojeda
0 siblings, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2021-11-08 11:10 UTC (permalink / raw)
To: Oliver Upton
Cc: Linux ARM, Mark Rutland, Marc Zyngier, Daniel Lezcano,
Nathan Chancellor, Nick Desaulniers, clang-built-linux,
kernel test robot
On Sun, Nov 7, 2021 at 10:11 AM 'Oliver Upton' via Clang Built Linux
<clang-built-linux@googlegroups.com> wrote:
>
> My inbox searching was poor, there is another thread on this issue
> where Miguel proposed tweaking the assertion such that clang no longer
> emits the warning. No longer having issues with the patch applied [1]
Glad it helped! The fix is in mainline now.
Cheers,
Miguel
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-08 11:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-07 9:01 [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning Oliver Upton
2021-11-07 9:11 ` Oliver Upton
2021-11-08 11:10 ` Miguel Ojeda
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox