From: Cong Ding <dinggnu@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: Gleb Natapov <gleb@redhat.com>,
Sasha Levin <levinsasha928@gmail.com>,
Asias He <asias.hejun@gmail.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] kvm tools: remove redundant "if" condition
Date: Sat, 19 Jan 2013 11:27:21 +0100 [thread overview]
Message-ID: <20130119102719.GA12013@gmail.com> (raw)
In-Reply-To: <CAOJsxLFHhKLxNcjwUO-tFrjZ5MYFhWdgBX-LHSkh28-SX1cE4Q@mail.gmail.com>
On Sat, Jan 19, 2013 at 10:58:33AM +0200, Pekka Enberg wrote:
> On Wed, Jan 16, 2013 at 6:52 PM, Cong Ding <dinggnu@gmail.com> wrote:
> > After we check (state.kcount != 0), state.kcount has to be 0 in all the "else"
> > branchs.
> >
> > Signed-off-by: Cong Ding <dinggnu@gmail.com>
> > ---
> > tools/kvm/hw/i8042.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/kvm/hw/i8042.c b/tools/kvm/hw/i8042.c
> > index 9f8be6a..9035732 100644
> > --- a/tools/kvm/hw/i8042.c
> > +++ b/tools/kvm/hw/i8042.c
> > @@ -189,7 +189,7 @@ static u32 kbd_read_data(void)
> > state.mcount--;
> > kvm__irq_line(state.kvm, AUX_IRQ, 0);
> > kbd_update_irq();
> > - } else if (state.kcount == 0) {
> > + } else {
> > i = state.kread - 1;
> > if (i < 0)
> > i = QUEUE_SIZE;
>
> This doesn't look right. The 'kcount' field is an int so the value can
> be negative.
But the former check is "state.kcount != 0" as I described in the commit
message. Notice the difference between variable names in the "if" condition: the
first one is kcount, the second one is mcount, and the third one is same as the
first one kcount.
Ok, the original code is
if (state.kcount != 0) {
/* do something when (state.kcount != 0) */
} else if (state.mcount > 0) {
/* do something when (state.kcount == 0 && state.mount > 0) */
} else if (state.kcount == 0) {
/* do something when (state.kcount == 0 && state.mount <= 0) */
}
For the third branch, it runs when state.kcount == 0 and state.mount <= 0,
it's not necessary to ensure state.kcount == 0 again.
- cong
next prev parent reply other threads:[~2013-01-19 10:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 1:07 [PATCH] kvm: close opened file Cong Ding
2013-01-16 1:07 ` [PATCH] kvm: remove redundant "if" condition Cong Ding
2013-01-16 11:35 ` [PATCH] kvm: close opened file Gleb Natapov
2013-01-16 16:51 ` [PATCH v2] kvm tools: " Cong Ding
2013-01-19 8:57 ` Pekka Enberg
2013-01-16 16:52 ` [PATCH v2] kvm tools: remove redundant "if" condition Cong Ding
2013-01-19 8:58 ` Pekka Enberg
2013-01-19 10:27 ` Cong Ding [this message]
2013-01-22 19:52 ` Pekka Enberg
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=20130119102719.GA12013@gmail.com \
--to=dinggnu@gmail.com \
--cc=asias.hejun@gmail.com \
--cc=gleb@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@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