From mboxrd@z Thu Jan 1 00:00:00 1970 From: Subrata Modak Subject: [PATCH][Resend] Fix Warnining in arch/x86/kvm/vmx.c Date: Wed, 13 May 2009 14:46:43 +0530 Message-ID: <20090513091643.8216.46699.sendpatchset@subratamodak.linux.ibm.com> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Sachin P Sant , Subrata Modak , Balbir Singh To: , Yaniv Kamay , Avi Kivity Return-path: Received: from e1.ny.us.ibm.com ([32.97.182.141]:51296 "EHLO e1.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753256AbZEMJRD (ORCPT ); Wed, 13 May 2009 05:17:03 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e1.ny.us.ibm.com (8.13.1/8.13.1) with ESMTP id n4D9DAEi026406 for ; Wed, 13 May 2009 05:13:10 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n4D9GmaS202180 for ; Wed, 13 May 2009 05:16:48 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n4D9GlJA013415 for ; Wed, 13 May 2009 05:16:47 -0400 Sender: kvm-owner@vger.kernel.org List-ID: Hi Avi/Yaniv, With gcc --version 4.4.1 20090429 (prerelease) I get the following warning: arch/x86/kvm/vmx.c: In function =E2=80=98vmx_intr_assist=E2=80=99: arch/x86/kvm/vmx.c:3233: warning: =E2=80=98max_irr=E2=80=99 may be used= uninitialized in this function arch/x86/kvm/vmx.c:3233: note: =E2=80=98max_irr=E2=80=99 was declared h= ere Investigation found that: 3231 static void update_tpr_threshold(struct kvm_vcpu *vcpu) 3232 { 3233 int max_irr, tpr; 3234=20 3235 if (!vm_need_tpr_shadow(vcpu->kvm)) 3236 return; 3237=20 3238 if (!kvm_lapic_enabled(vcpu) || 3239 ((max_irr =3D kvm_lapic_find_highest_irr(vcpu)) =3D=3D= -1)) { (max_irr =3D kvm_lapic_find_highest_irr(vcpu)) =3D=3D -1 may not get a chance to evaluate if: !kvm_lapic_enabled(vcpu) evaluates to true (as the expressions are Or-ed). 3240 vmcs_write32(TPR_THRESHOLD, 0); 3241 return; 3242 } 3243=20 3244 tpr =3D (kvm_lapic_get_cr8(vcpu) & 0x0f) << 4; 3245 vmcs_write32(TPR_THRESHOLD, (max_irr > tpr) ? tpr >> 4 : m= ax_irr >> 4); Using (max_irr > tpr) and max_irr >> 4, without max_irr getting initial= ized can cause trouble. 3246 } I would like to propose a small fix for this by interchanging the operands in ||, so that max_irr is initialized in all instances, and, the warning fades away, without compromising the criteria of conditional evaluation inside if(). Signed-Off-By: Subrata Modak , To: Avi Kivity To: Yaniv Kamay To: Cc: Balbir Singh Cc: Sachin P Sant Subject: [PATCH][Resend] Fix Warnining in arch/x86/kvm/vmx.c --- --- a/arch/x86/kvm/vmx.c 2009-05-12 15:28:42.000000000 +0530 +++ b/arch/x86/kvm/vmx.c 2009-05-12 15:51:02.000000000 +0530 @@ -3235,8 +3235,8 @@ static void update_tpr_threshold(struct=20 if (!vm_need_tpr_shadow(vcpu->kvm)) return; =20 - if (!kvm_lapic_enabled(vcpu) || - ((max_irr =3D kvm_lapic_find_highest_irr(vcpu)) =3D=3D -1)) { + if (((max_irr =3D kvm_lapic_find_highest_irr(vcpu)) =3D=3D -1) || + !kvm_lapic_enabled(vcpu)) { vmcs_write32(TPR_THRESHOLD, 0); return; } --- Regards-- Subrata