Skip to contentSkip to conversation

x86: Fix unused variable 'hi'

PATCH In review Xu Yihang 4 participants 8 messages Mar 18, 2021 – Mar 24, 2021 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Xu Yihang

author
#0 lore raw

PATCH 1/1 x86: Fix unused variable 'hi'

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

---
 arch/x86/hyperv/hv_apic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/hyperv/hv_apic.c +2 -1
index 284e73661a18..c0b0a5774f31 100644
@@ -55,7 +55,8 @@ static void hv_apic_icr_write(u32 low, u32 id)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	u32 hi __maybe_unused;
+	u32 reg_val;
 
 	switch (reg) {
 	case APIC_EOI:
Signature · 1 line
2.17.1
#1 lore raw
Quoted 14 lines · Xu Yihang

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

---
 arch/x86/hyperv/hv_apic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/hyperv/hv_apic.c +0 -0
index 284e73661a18..c0b0a5774f31 100644

arch/x86/hyperv/hv_apic.c static void hv_apic_icr_write(u32 low, u32 id) · line 62

Quoted 9 lines
arch/x86/hyperv/hv_apic.c +2 -1
@@ -55,7 +55,8 @@ static void hv_apic_icr_write(u32 low, u32 id)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	u32 hi __maybe_unused;
+	u32 reg_val;
 
 	switch (reg) {
 	case APIC_EOI:

Why and under what config does this function trigger the warning?

Thanks,

Ingo

#2 lore raw

From: Ingo Molnar <[email protected]> Sent: Thursday, March 18, 2021 4:24 AM

Quoted 25 lines · Xu Yihang
Quoted 3 lines

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-

set-variable]

Quoted 19 lines
---
 arch/x86/hyperv/hv_apic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/hyperv/hv_apic.c +2 -1
index 284e73661a18..c0b0a5774f31 100644
@@ -55,7 +55,8 @@ static void hv_apic_icr_write(u32 low, u32 id)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	u32 hi __maybe_unused;
+	u32 reg_val;
 
Quoted 8 lines

arch/x86/hyperv/hv_apic.c static void hv_apic_icr_write(u32 low, u32 id) · line 62

Quoted 2 lines
arch/x86/hyperv/hv_apic.c +0 -0
 	switch (reg) {
 	case APIC_EOI:

Why and under what config does this function trigger the warning?

Thanks,

Ingo

The warning should trigger if CONFIG_HYPERV is "m" or "y", and W=1 is selected. The variable is indeed set but not used because only the low order 32 bits of the synthetic MSR are relevant, but rdmsr() returns both the low 32 and the high 32 bits.

Michael

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw

PATCH 1/1 x86: Fix unused variable 'hi'

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

Compiled with CONFIG_HYPERV enabled:
make allmodconfig ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- make W=1 arch/x86/hyperv/hv_apic.o ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

HV_X64_MSR_EOI stores on bit 31:0 and HV_X64_MSR_TPR stores in bit 7:0, which means higher 32 bits are not really used, therefore __maybe_unused added.

---
 arch/x86/hyperv/hv_apic.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/hyperv/hv_apic.c +2 -1
index 284e73661a18..c0b0a5774f31 100644
@@ -55,7 +55,8 @@ static void hv_apic_icr_write(u32 low, u32 id)
 
 static u32 hv_apic_read(u32 reg)
 {
-	u32 reg_val, hi;
+	u32 hi __maybe_unused;
+	u32 reg_val;
 
 	switch (reg) {
 	case APIC_EOI:
Signature · 1 line
2.17.1
maintainer
#5 lore raw
Quoted 11 lines · Xu Yihang

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

Compiled with CONFIG_HYPERV enabled:
make allmodconfig ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- make W=1 arch/x86/hyperv/hv_apic.o ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

HV_X64_MSR_EOI stores on bit 31:0 and HV_X64_MSR_TPR stores in bit 7:0, which means higher 32 bits are not really used, therefore __maybe_unused added.

I slightly modified the commit message and queued it up for hyperv-next. Thanks.

Wei.

author
#6 lore raw

PATCH 1/1 x86: Fix unused variable 'hi'

In reply to Xu Yihang

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

Compiled with CONFIG_HYPERV enabled:
make allmodconfig ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- make W=1 arch/x86/hyperv/hv_apic.o ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

HV_X64_MSR_EOI stores on bit 31:0 and HV_X64_MSR_TPR stores in bit 7:0, which means higher 32 bits are not really used, therefore potentially cast to void in order to silent this warning.

---
 arch/x86/hyperv/hv_apic.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/hyperv/hv_apic.c +2 -0
index 284e73661a18..a8b639498033 100644
@@ -60,9 +60,11 @@ static u32 hv_apic_read(u32 reg)
 	switch (reg) {
 	case APIC_EOI:
 		rdmsr(HV_X64_MSR_EOI, reg_val, hi);
+		(void) hi;
 		return reg_val;
 	case APIC_TASKPRI:
 		rdmsr(HV_X64_MSR_TPR, reg_val, hi);
+		(void) hi;
 		return reg_val;
 
 	default:
Signature · 1 line
2.17.1
maintainer
#7 lore raw
Quoted 21 lines · Xu Yihang

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

Compiled with CONFIG_HYPERV enabled:
make allmodconfig ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- make W=1 arch/x86/hyperv/hv_apic.o ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

HV_X64_MSR_EOI stores on bit 31:0 and HV_X64_MSR_TPR stores in bit 7:0, which means higher 32 bits are not really used, therefore potentially cast to void in order to silent this warning.

---
 arch/x86/hyperv/hv_apic.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/hyperv/hv_apic.c +0 -0
index 284e73661a18..a8b639498033 100644

arch/x86/hyperv/hv_apic.c static u32 hv_apic_read(u32 reg) · line 67

Quoted 8 lines
arch/x86/hyperv/hv_apic.c +2 -0
@@ -60,9 +60,11 @@ static u32 hv_apic_read(u32 reg)
 	switch (reg) {
 	case APIC_EOI:
 		rdmsr(HV_X64_MSR_EOI, reg_val, hi);
+		(void) hi;
 		return reg_val;
 	case APIC_TASKPRI:
 		rdmsr(HV_X64_MSR_TPR, reg_val, hi);
+		(void) hi;

I would like to remove the space while committing this patch. There is no need for you to do anything.

Wei.

Quoted 6 lines
arch/x86/hyperv/hv_apic.c +0 -0
 		return reg_val;
 
 	default:
Signature · 1 line
2.17.1
maintainer Applied
#8 lore raw
Quoted 17 lines · Wei Liu
Quoted 16 lines · Xu Yihang

Fixes the following W=1 kernel build warning(s):
arch/x86/hyperv/hv_apic.c:58:15: warning: variable ‘hi’ set but not used [-Wunused-but-set-variable]

Compiled with CONFIG_HYPERV enabled:
make allmodconfig ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu- make W=1 arch/x86/hyperv/hv_apic.o ARCH=x86_64 CROSS_COMPILE=x86_64-linux-gnu-

HV_X64_MSR_EOI stores on bit 31:0 and HV_X64_MSR_TPR stores in bit 7:0, which means higher 32 bits are not really used, therefore potentially cast to void in order to silent this warning.

---
 arch/x86/hyperv/hv_apic.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 16 lines

arch/x86/hyperv/hv_apic.c static u32 hv_apic_read(u32 reg) · line 67

Quoted 13 lines
arch/x86/hyperv/hv_apic.c +2 -0
index 284e73661a18..a8b639498033 100644
@@ -60,9 +60,11 @@ static u32 hv_apic_read(u32 reg)
 	switch (reg) {
 	case APIC_EOI:
 		rdmsr(HV_X64_MSR_EOI, reg_val, hi);
+		(void) hi;
 		return reg_val;
 	case APIC_TASKPRI:
 		rdmsr(HV_X64_MSR_TPR, reg_val, hi);
+		(void) hi;

I would like to remove the space while committing this patch. There is no need for you to do anything.

Applied to hyperv-next.