public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Oliver Upton <oupton@google.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Mark Rutland <mark.rutland@arm.com>,
	Marc Zyngier <maz@kernel.org>,
	 Daniel Lezcano <daniel.lezcano@linaro.org>,
	Nathan Chancellor <nathan@kernel.org>,
	 Nick Desaulniers <ndesaulniers@google.com>,
	clang-built-linux@googlegroups.com,
	Oliver Upton <oupton@google.com>,
	kernel test robot <lkp@intel.com>
Subject: [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning
Date: Sun,  7 Nov 2021 09:01:45 +0000	[thread overview]
Message-ID: <20211107090144.3172241-1-oupton@google.com> (raw)

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

             reply	other threads:[~2021-11-07  9:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07  9:01 Oliver Upton [this message]
2021-11-07  9:11 ` [PATCH] clocksource/arm_arch_timer: Fix bogus -Wsometimes-uninitialized warning Oliver Upton
2021-11-08 11:10   ` Miguel Ojeda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211107090144.3172241-1-oupton@google.com \
    --to=oupton@google.com \
    --cc=clang-built-linux@googlegroups.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=lkp@intel.com \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox