From: Paolo Bonzini <pbonzini@redhat.com>
To: Michael Tokarev <mjt@tls.msk.ru>,
Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>,
Gleb Natapov <gleb@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables
Date: Tue, 03 Jun 2014 15:11:20 +0200 [thread overview]
Message-ID: <538DC978.5040300@redhat.com> (raw)
In-Reply-To: <538DC844.2040808@msgid.tls.msk.ru>
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_strandqvist@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) & 0xffffffff);
>> ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
>> (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
>> outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
>> (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
>> }
>> #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) & 0xffffffff);
> ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
> (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
> outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
> (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
> }
> 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
prev parent reply other threads:[~2014-06-03 13:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-31 23:05 [PATCH] arch: x86: kvm: x86.c: Cleaning up uninitialized variables Rickard Strandqvist
2014-06-03 12:04 ` Paolo Bonzini
2014-06-03 13:06 ` Michael Tokarev
2014-06-03 13:11 ` Paolo Bonzini [this message]
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=538DC978.5040300@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@kernel.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=rickard_strandqvist@spectrumdigital.se \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/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