Skip to contentSkip to conversation

x86: Fix unused variable 'msr_val' warning

PATCH In review Xu Yihang 2 participants 2 messages Mar 18, 2021 – Mar 19, 2021

Subsystems (3)
lore
Share & tools
lore

Xu Yihang

author
#0 lore raw

PATCH 1/1 x86: Fix unused variable 'msr_val' warning

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_spinlock.c:28:16: warning: variable ‘msr_val’ set but not used [-Wunused-but-set-variable]
unsigned long msr_val;

---
 arch/x86/hyperv/hv_spinlock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_spinlock.c +1 -1
index f3270c1fc48c..67bc15c7752a 100644
@@ -25,7 +25,7 @@ static void hv_qlock_kick(int cpu)
 
 static void hv_qlock_wait(u8 *byte, u8 val)
 {
-	unsigned long msr_val;
+	unsigned long msr_val __maybe_unused;
 	unsigned long flags;
 
 	if (in_nmi())
Signature · 1 line
2.17.1
#1 lore raw

From: Xu Yihang <[email protected]> Sent: Thursday, March 18, 2021 1:04 AM

Quoted 26 lines

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_spinlock.c:28:16: warning: variable ‘msr_val’ set but not used [- Wunused-but-set-variable]
unsigned long msr_val;

---
 arch/x86/hyperv/hv_spinlock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/hyperv/hv_spinlock.c +1 -2
index f3270c1fc48c..67bc15c7752a 100644
@@ -25,7 +25,7 @@ static void hv_qlock_kick(int cpu)
 
 static void hv_qlock_wait(u8 *byte, u8 val)
 {
-	unsigned long msr_val;
+	unsigned long msr_val __maybe_unused;
 	unsigned long flags;
 
 	if (in_nmi())
--
Quoted 1 line

2.17.1

This is one of those slightly weird cases where the side effect of reading the synthetic MSR provided by Hyper-V is what we want. The returned value is irrelevant and never used, so the __maybe_unused annotation is correct.

Let me suggest updating the commit message, and adding a brief comment to the code to explain this. The side effect behavior is described in the Hyper-V TLFS, though perhaps not as clearly as it should be.

Michael