Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Michael Tokarev
03.06.2014 16:04, Paolo Bonzini wrote:
> Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:
>> There is a risk that the variable will be used without being initialized.
>>
>> This was largely found by using a static code analysis program called 
>> cppcheck.
>>
>> Signed-off-by: Rickard Strandqvist 
> 
> No, there isn't.  The full context looks like this:
> 
> longmode = is_long_mode(vcpu) && cs_l == 1;
> if (!longmode) {
> param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
> (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0x);
> ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
> (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0x);
> outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
> (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
> }
> #ifdef CONFIG_X86_64
> else {
> param = kvm_register_read(vcpu, VCPU_REGS_RCX);
> ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
> outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
> }
> #endif
> 
> and longmode must be zero if !CONFIG_X86_64:

This is not the first time this code is attempted to be changed.

Maybe adding an additional #ifdef..endif around the longmode
assignment and the "if" above will solve this for good?

Or maybe something like this:

 #ifdef CONFIG_X86_64
 if (!(is_long_mode(vcpu) && cs_l == 1)) {
 #else
 if (1) {
 #endif
 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0x);
 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0x);
 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
 }
 else {
 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
 }

, to make it all explicit and obvious?

Thanks,

/mjt

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Paolo Bonzini

Il 03/06/2014 15:06, Michael Tokarev ha scritto:

03.06.2014 16:04, Paolo Bonzini wrote:

Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:

There is a risk that the variable will be used without being initialized.

This was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist 


No, there isn't.  The full context looks like this:

longmode = is_long_mode(vcpu) && cs_l == 1;
if (!longmode) {
param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0x);
ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0x);
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
}
#ifdef CONFIG_X86_64
else {
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
}
#endif

and longmode must be zero if !CONFIG_X86_64:


This is not the first time this code is attempted to be changed.

Maybe adding an additional #ifdef..endif around the longmode
assignment and the "if" above will solve this for good?

Or maybe something like this:

 #ifdef CONFIG_X86_64
 if (!(is_long_mode(vcpu) && cs_l == 1)) {
 #else
 if (1) {
 #endif
 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0x);
 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0x);
 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
 (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
 }
 else {
 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
 }

, to make it all explicit and obvious?


... and ugly too.

If the first person who got the answer had reported a bug against 
cppcheck, this perhaps would have been avoided.


Paolo

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Paolo Bonzini
Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:
> There is a risk that the variable will be used without being initialized.
> 
> This was largely found by using a static code analysis program called 
> cppcheck.
> 
> Signed-off-by: Rickard Strandqvist 

No, there isn't.  The full context looks like this:

longmode = is_long_mode(vcpu) && cs_l == 1;
if (!longmode) {
param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RAX) & 0x);
ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RCX) & 0x);
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
}
#ifdef CONFIG_X86_64
else {
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
}
#endif

and longmode must be zero if !CONFIG_X86_64:

static inline int is_long_mode(struct kvm_vcpu *vcpu)
{
#ifdef CONFIG_X86_64
return vcpu->arch.efer & EFER_LMA;
#else
return 0;
#endif
}

So it's the static checker that cannot understand #ifdef well
enough and ought to be fixed.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Paolo Bonzini
Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:
 There is a risk that the variable will be used without being initialized.
 
 This was largely found by using a static code analysis program called 
 cppcheck.
 
 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se

No, there isn't.  The full context looks like this:

longmode = is_long_mode(vcpu)  cs_l == 1;
if (!longmode) {
param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RAX)  0x);
ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RCX)  0x);
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
}
#ifdef CONFIG_X86_64
else {
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
}
#endif

and longmode must be zero if !CONFIG_X86_64:

static inline int is_long_mode(struct kvm_vcpu *vcpu)
{
#ifdef CONFIG_X86_64
return vcpu-arch.efer  EFER_LMA;
#else
return 0;
#endif
}

So it's the static checker that cannot understand #ifdef well
enough and ought to be fixed.

Paolo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Paolo Bonzini

Il 03/06/2014 15:06, Michael Tokarev ha scritto:

03.06.2014 16:04, Paolo Bonzini wrote:

Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:

There is a risk that the variable will be used without being initialized.

This was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se


No, there isn't.  The full context looks like this:

longmode = is_long_mode(vcpu)  cs_l == 1;
if (!longmode) {
param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RAX)  0x);
ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RCX)  0x);
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
}
#ifdef CONFIG_X86_64
else {
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
}
#endif

and longmode must be zero if !CONFIG_X86_64:


This is not the first time this code is attempted to be changed.

Maybe adding an additional #ifdef..endif around the longmode
assignment and the if above will solve this for good?

Or maybe something like this:

 #ifdef CONFIG_X86_64
 if (!(is_long_mode(vcpu)  cs_l == 1)) {
 #else
 if (1) {
 #endif
 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RAX)  0x);
 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RCX)  0x);
 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
 }
 else {
 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
 }

, to make it all explicit and obvious?


... and ugly too.

If the first person who got the answer had reported a bug against 
cppcheck, this perhaps would have been avoided.


Paolo

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-06-03 Thread Michael Tokarev
03.06.2014 16:04, Paolo Bonzini wrote:
 Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:
 There is a risk that the variable will be used without being initialized.

 This was largely found by using a static code analysis program called 
 cppcheck.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 
 No, there isn't.  The full context looks like this:
 
 longmode = is_long_mode(vcpu)  cs_l == 1;
 if (!longmode) {
 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RAX)  0x);
 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RCX)  0x);
 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
 }
 #ifdef CONFIG_X86_64
 else {
 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
 }
 #endif
 
 and longmode must be zero if !CONFIG_X86_64:

This is not the first time this code is attempted to be changed.

Maybe adding an additional #ifdef..endif around the longmode
assignment and the if above will solve this for good?

Or maybe something like this:

 #ifdef CONFIG_X86_64
 if (!(is_long_mode(vcpu)  cs_l == 1)) {
 #else
 if (1) {
 #endif
 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RAX)  0x);
 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RCX)  0x);
 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
 (kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
 }
 else {
 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
 }

, to make it all explicit and obvious?

Thanks,

/mjt

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-05-31 Thread Rickard Strandqvist
There is a risk that the variable will be used without being initialized.

This was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist 
---
 arch/x86/kvm/x86.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 20316c6..88bf642 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5691,13 +5691,17 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI) & 0x);
}
-#ifdef CONFIG_X86_64
else {
+#ifdef CONFIG_X86_64
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
-   }
+#else
+   param = 0;
+   ingpa = 0;
+   outgpa = 0;
 #endif
+   }
 
code = param & 0x;
fast = (param >> 16) & 0x1;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables

2014-05-31 Thread Rickard Strandqvist
There is a risk that the variable will be used without being initialized.

This was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 arch/x86/kvm/x86.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 20316c6..88bf642 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5691,13 +5691,17 @@ int kvm_hv_hypercall(struct kvm_vcpu *vcpu)
outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI)  32) |
(kvm_register_read(vcpu, VCPU_REGS_RSI)  0x);
}
-#ifdef CONFIG_X86_64
else {
+#ifdef CONFIG_X86_64
param = kvm_register_read(vcpu, VCPU_REGS_RCX);
ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
-   }
+#else
+   param = 0;
+   ingpa = 0;
+   outgpa = 0;
 #endif
+   }
 
code = param  0x;
fast = (param  16)  0x1;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/