Skip to contentSkip to conversation

x86: KVM: Fix warnings by returning bool

PATCH In review Emil Goode 4 participants 6 messages Jan 27, 2013 – Jan 29, 2013

Subsystems (6)
x86 KVM Sound Kernel janitors +2 more subsystems
lore
Share & tools
lore

Emil Goode

author
#0 lore raw

PATCH 1/3 x86: KVM: Fix warnings by returning bool

The function pointer x2apic_available in struct hypervisor_x86 is supposed to point to functions that return bool. This patch changes the return type of the kvm_para_available function to bool.

Sparse warnings:

arch/x86/kernel/kvm.c:508:35: warning:
incorrect type in initializer (different signedness) arch/x86/kernel/kvm.c:508:35:
expected bool ( *x2apic_available )( ... ) arch/x86/kernel/kvm.c:508:35:
got int ( static inline [toplevel] *<noident> )( ... )

arch/x86/kernel/kvm.c:508:2: warning:
initialization from incompatible pointer type [enabled by default]

arch/x86/kernel/kvm.c:508:2: warning:
(near initialization for ‘x86_hyper_kvm.x2apic_available’) [enabled by default]

---
 arch/x86/include/asm/kvm_para.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/kvm_para.h +4 -4
index 0be7039..695399f 100644
@@ -85,13 +85,13 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
 	return ret;
 }
 
-static inline int kvm_para_available(void)
+static inline bool kvm_para_available(void)
 {
 	unsigned int eax, ebx, ecx, edx;
 	char signature[13];
 
 	if (boot_cpu_data.cpuid_level < 0)
-		return 0;	/* So we don't blow up on old processors */
+		return false;	/* So we don't blow up on old processors */
 
 	if (cpu_has_hypervisor) {
 		cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
@@ -101,10 +101,10 @@ static inline int kvm_para_available(void)
 		signature[12] = 0;
 
 		if (strcmp(signature, "KVMKVMKVM") == 0)
-			return 1;
+			return true;
 	}
 
-	return 0;
+	return false;
 }
 
 static inline unsigned int kvm_arch_para_features(void)
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 2/3 x86: KVM: Simplify function kvm_detect

The first patch in this series changed the kvm_para_available function to return bool. We can now simplify the kvm_detect function by directly returning the return value of kvm_para_available.

---
 arch/x86/kernel/kvm.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/x86/kernel/kvm.c +1 -3
index 2b44ea5..3644908 100644
@@ -497,9 +497,7 @@ void __init kvm_guest_init(void)
 
 static bool __init kvm_detect(void)
 {
-	if (!kvm_para_available())
-		return false;
-	return true;
+	return kvm_para_available();
 }
 
 const struct hypervisor_x86 x86_hyper_kvm __refconst = {
Signature · 1 line
1.7.10.4
author
#2 lore raw

PATCH 3/3 ALSA: intel8x0: Check return value before assigning

In reply to Emil Goode

The first patch in this series changes the return type of function kvm_para_available to bool. In the function snd_intel8x0_inside_vm we now need to check it's return value before assigning a value to the result variable.

---
 sound/pci/intel8x0.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/intel8x0.c +1 -1
index 3b9be75..fa9337e 100644
@@ -2982,7 +2982,7 @@ static int snd_intel8x0_inside_vm(struct pci_dev *pci)
 	}
 
 	/* detect KVM and Parallels virtual environments */
-	result = kvm_para_available();
+	result = kvm_para_available() ? 1 : 0;
 #ifdef X86_FEATURE_HYPERVISOR
 	result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR);
 #endif
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH 3/3] ALSA: intel8x0: Check return value before assigning

Wtf?

This patch seems semibogus at best and the description is even more ridiculous...

Quoted 24 lines · Emil Goode

The first patch in this series changes the return type of function kvm_para_available to bool. In the function snd_intel8x0_inside_vm we now need to check it's return value before assigning a value to the result variable.

---
sound/pci/intel8x0.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/intel8x0.c +1 -1
index 3b9be75..fa9337e 100644
@@ -2982,7 +2982,7 @@ static int snd_intel8x0_inside_vm(struct pci_dev
 *pci)
 	}
 
 	/* detect KVM and Parallels virtual environments */
-	result = kvm_para_available();
+	result = kvm_para_available() ? 1 : 0;
 #ifdef X86_FEATURE_HYPERVISOR
 	result = result || boot_cpu_has(X86_FEATURE_HYPERVISOR);

#endif

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#4 lore raw

Re: [PATCH 3/3] ALSA: intel8x0: Check return value before assigning

In reply to Emil Goode

At Sun, 27 Jan 2013 17:40:02 +0100,

Quoted 16 lines · Emil Goode

The first patch in this series changes the return type of function kvm_para_available to bool. In the function snd_intel8x0_inside_vm we now need to check it's return value before assigning a value to the result variable.

---
 sound/pci/intel8x0.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/intel8x0.c +0 -0
index 3b9be75..fa9337e 100644

sound/pci/intel8x0.c static int snd_intel8x0_inside_vm(struct pci_dev *pci) · line 2985

Quoted 5 lines
sound/pci/intel8x0.c +1 -1
@@ -2982,7 +2982,7 @@ static int snd_intel8x0_inside_vm(struct pci_dev *pci)
 	}
 
 	/* detect KVM and Parallels virtual environments */
-	result = kvm_para_available();
+	result = kvm_para_available() ? 1 : 0;

This is superfluous. The conversion from bool to int works implicitly like that.

Takashi

#5 lore raw
In reply to Emil Goode
Quoted 13 lines · Emil Goode

The function pointer x2apic_available in struct hypervisor_x86 is supposed to point to functions that return bool. This patch changes the return type of the kvm_para_available function to bool.

Sparse warnings:

arch/x86/kernel/kvm.c:508:35: warning:
incorrect type in initializer (different signedness) arch/x86/kernel/kvm.c:508:35:
expected bool ( *x2apic_available )( ... ) arch/x86/kernel/kvm.c:508:35:
got int ( static inline [toplevel] *<noident> )( ... )

Quoted 7 lines

arch/x86/kernel/kvm.c:508:2: warning:
initialization from incompatible pointer type [enabled by default]

arch/x86/kernel/kvm.c:508:2: warning:
(near initialization for ‘x86_hyper_kvm.x2apic_available’) [enabled by default]

The breakage was in tip x86/apic tree only and it was fixed by 3b4a505821 there.

Quoted 40 lines
---
 arch/x86/include/asm/kvm_para.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/include/asm/kvm_para.h +4 -4
index 0be7039..695399f 100644
@@ -85,13 +85,13 @@ static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
 	return ret;
 }
 
-static inline int kvm_para_available(void)
+static inline bool kvm_para_available(void)
 {
 	unsigned int eax, ebx, ecx, edx;
 	char signature[13];
 
 	if (boot_cpu_data.cpuid_level < 0)
-		return 0;	/* So we don't blow up on old processors */
+		return false;	/* So we don't blow up on old processors */
 
 	if (cpu_has_hypervisor) {
 		cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
@@ -101,10 +101,10 @@ static inline int kvm_para_available(void)
 		signature[12] = 0;
 
 		if (strcmp(signature, "KVMKVMKVM") == 0)
-			return 1;
+			return true;
 	}
 
-	return 0;
+	return false;
 }
 
 static inline unsigned int kvm_arch_para_features(void)
Signature · 1 line
1.7.10.4

--
Gleb.