From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael S. Tsirkin" Subject: [PATCH] kvm: disable uninitialized var warning Date: Sun, 3 Jun 2012 11:34:08 +0300 Message-ID: <20120603083408.GA2183@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE To: kvm@vger.kernel.org, yoshikawa.takuya@oss.ntt.co.jp Return-path: Received: from mx1.redhat.com ([209.132.183.28]:55931 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757026Ab2FCIeJ (ORCPT ); Sun, 3 Jun 2012 04:34:09 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: I see this in 3.5-rc1: arch/x86/kvm/mmu.c: In function =E2=80=98kvm_test_age_rmapp=E2=80=99:=20 arch/x86/kvm/mmu.c:1271: warning: =E2=80=98iter.desc=E2=80=99 may be us= ed uninitialized in this function The line in question was introduced by commit 1e3f42f03c38c29c1814199a6f0a2f01b919ea3f static int kvm_test_age_rmapp(struct kvm *kvm, unsigned long *rmapp, unsigned long data) { - u64 *spte; + u64 *sptep; + struct rmap_iterator iter; <- line 1271 int young =3D 0; =20 /* The reason I think is that the compiler assumes that the rmap value could be 0, so static u64 *rmap_get_first(unsigned long rmap, struct rmap_iterator *iter) { if (!rmap) return NULL; if (!(rmap & 1)) { iter->desc =3D NULL; return (u64 *)rmap; } iter->desc =3D (struct pte_list_desc *)(rmap & ~1ul); iter->pos =3D 0; return iter->desc->sptes[iter->pos]; } will not initialize iter.desc, but the compiler isn't smart enough to see that for (sptep =3D rmap_get_first(*rmapp, &iter); sptep; sptep =3D rmap_get_next(&iter)) { will immediately exit in this case. I checked by adding if (!*rmapp) goto out; on top which is clearly equivalent but disables the warning. This patch uses uninitialized_var to disable the warning without increasing code size. Signed-off-by: Michael S. Tsirkin --- diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index be3cea4..dc83761 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -1238,7 +1238,7 @@ static int kvm_age_rmapp(struct kvm *kvm, unsigne= d long *rmapp, unsigned long data) { u64 *sptep; - struct rmap_iterator iter; + struct rmap_iterator uninitialized_var(iter); int young =3D 0; =20 /* --=20 MST