From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cong Ding Subject: Re: [PATCH v2] kvm tools: remove redundant "if" condition Date: Sat, 19 Jan 2013 11:27:21 +0100 Message-ID: <20130119102719.GA12013@gmail.com> References: <1358298456-18377-1-git-send-email-dinggnu@gmail.com> <20130116113522.GR11529@redhat.com> <20130116165239.GB18593@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Gleb Natapov , Sasha Levin , Asias He , kvm@vger.kernel.org, linux-kernel@vger.kernel.org To: Pekka Enberg Return-path: Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org On Sat, Jan 19, 2013 at 10:58:33AM +0200, Pekka Enberg wrote: > On Wed, Jan 16, 2013 at 6:52 PM, Cong Ding wrote: > > After we check (state.kcount != 0), state.kcount has to be 0 in all the "else" > > branchs. > > > > Signed-off-by: Cong Ding > > --- > > 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