From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cyrill Gorcunov Subject: Re: [PATCH] kvm tools: Use assert() helper to check a variable value Date: Mon, 19 Dec 2011 12:25:45 +0400 Message-ID: <20111219082545.GE17380@moon> References: <20111218213536.GB17380@moon> <20111219075738.GD17380@moon> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Sasha Levin , Asias He , Ingo Molnar , Thomas Gleixner , KVM-ML To: Pekka Enberg Return-path: Received: from mail-ee0-f46.google.com ([74.125.83.46]:62775 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751501Ab1LSIZu (ORCPT ); Mon, 19 Dec 2011 03:25:50 -0500 Received: by eekc4 with SMTP id c4so5201832eek.19 for ; Mon, 19 Dec 2011 00:25:49 -0800 (PST) Content-Disposition: inline In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Dec 19, 2011 at 10:19:43AM +0200, Pekka Enberg wrote: > On Mon, Dec 19, 2011 at 09:13:28AM +0200, Pekka Enberg wrote: > >> > > >> >- =A0 =A0BUILD_BUG_ON(i > E820_X_MAX); > >> >+ =A0 =A0assert(i <=3D E820_X_MAX); > >> > >> We should use BUG_ON() like tools/perf does. >=20 > On Mon, Dec 19, 2011 at 9:57 AM, Cyrill Gorcunov = wrote: > > We dont have it yet. So I'll introduce this helper later, > > but note that we will have to cover _all_ assert() calls then, > > so it's better to make in a separate patch. Meanwhile such fix > > it better than bug ;) >=20 > You don't need to convert all of them at the same time but we're not > adding new assert() calls. >=20 You both (Pekka and Ingo) know the way how to convince people ;) Something like below? Cyrill --- kvm tools: Add BUG_ON() helper to make a run-time critical tests Also drop useless assert.h inclusions. Signed-off-by: Cyrill Gorcunov --- tools/kvm/include/kvm/util.h | 5 ++++- tools/kvm/ioport.c | 1 - tools/kvm/kvm-cmd.c | 6 ++---- tools/kvm/kvm.c | 1 - tools/kvm/pci.c | 6 ++---- tools/kvm/powerpc/kvm.c | 1 - tools/kvm/virtio/console.c | 3 +-- tools/kvm/virtio/net.c | 1 - tools/kvm/x86/bios.c | 2 +- tools/kvm/x86/cpuid.c | 1 - tools/kvm/x86/kvm.c | 1 - 11 files changed, 10 insertions(+), 18 deletions(-) Index: linux-2.6.git/tools/kvm/include/kvm/util.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/include/kvm/util.h +++ linux-2.6.git/tools/kvm/include/kvm/util.h @@ -9,6 +9,7 @@ * Some bits are stolen from perf tool :) */ =20 +#include #include #include #include @@ -50,7 +51,9 @@ extern void set_die_routine(void (*routi __func__, __LINE__, ##__VA_ARGS__); \ } while (0) =20 -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)= ])) +# +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)= ])) +#define BUG_ON(condition) assert(!(condition)) =20 #define DIE_IF(cnd) \ do { \ Index: linux-2.6.git/tools/kvm/ioport.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/ioport.c +++ linux-2.6.git/tools/kvm/ioport.c @@ -10,7 +10,6 @@ #include =20 #include -#include #include #include #include Index: linux-2.6.git/tools/kvm/kvm-cmd.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/kvm-cmd.c +++ linux-2.6.git/tools/kvm/kvm-cmd.c @@ -2,8 +2,6 @@ #include #include =20 -#include - /* user defined header files */ #include "kvm/builtin-debug.h" #include "kvm/builtin-pause.h" @@ -71,14 +69,14 @@ int handle_command(struct cmd_struct *co =20 if (!argv || !*argv) { p =3D kvm_get_command(command, "help"); - assert(p); + BUG_ON(!p); return p->fn(argc, argv, prefix); } =20 p =3D kvm_get_command(command, argv[0]); if (!p) { p =3D kvm_get_command(command, "help"); - assert(p); + BUG_ON(!p); p->fn(0, NULL, prefix); return EINVAL; } Index: linux-2.6.git/tools/kvm/kvm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/kvm.c +++ linux-2.6.git/tools/kvm/kvm.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include Index: linux-2.6.git/tools/kvm/pci.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/pci.c +++ linux-2.6.git/tools/kvm/pci.c @@ -3,8 +3,6 @@ #include "kvm/util.h" #include "kvm/kvm.h" =20 -#include - #define PCI_BAR_OFFSET(b) (offsetof(struct pci_device_header, bar[b])= ) =20 static struct pci_device_header *pci_devices[PCI_MAX_DEVICES]; @@ -170,13 +168,13 @@ void pci__config_rd(struct kvm *kvm, uni =20 void pci__register(struct pci_device_header *dev, u8 dev_num) { - assert(dev_num < PCI_MAX_DEVICES); + BUG_ON(dev_num >=3D PCI_MAX_DEVICES); pci_devices[dev_num] =3D dev; } =20 struct pci_device_header *pci__find_dev(u8 dev_num) { - assert(dev_num < PCI_MAX_DEVICES); + BUG_ON(dev_num >=3D PCI_MAX_DEVICES); return pci_devices[dev_num]; } =20 Index: linux-2.6.git/tools/kvm/powerpc/kvm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/powerpc/kvm.c +++ linux-2.6.git/tools/kvm/powerpc/kvm.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include Index: linux-2.6.git/tools/kvm/virtio/console.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/virtio/console.c +++ linux-2.6.git/tools/kvm/virtio/console.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include =20 @@ -136,7 +135,7 @@ static int init_vq(struct kvm *kvm, void struct virt_queue *queue; void *p; =20 - assert(vq < VIRTIO_CONSOLE_NUM_QUEUES); + BUG_ON(vq >=3D VIRTIO_CONSOLE_NUM_QUEUES); =20 compat__remove_message(compat_id); =20 Index: linux-2.6.git/tools/kvm/virtio/net.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/virtio/net.c +++ linux-2.6.git/tools/kvm/virtio/net.c @@ -19,7 +19,6 @@ #include =20 #include -#include #include =20 #include Index: linux-2.6.git/tools/kvm/x86/bios.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/x86/bios.c +++ linux-2.6.git/tools/kvm/x86/bios.c @@ -98,7 +98,7 @@ static void e820_setup(struct kvm *kvm) }; } =20 - BUILD_BUG_ON(i > E820_X_MAX); + BUG_ON(i > E820_X_MAX); =20 e820->nr_map =3D i; } Index: linux-2.6.git/tools/kvm/x86/cpuid.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/x86/cpuid.c +++ linux-2.6.git/tools/kvm/x86/cpuid.c @@ -5,7 +5,6 @@ =20 #include #include -#include =20 #define CPUID_FUNC_PERFMON 0x0A =20 Index: linux-2.6.git/tools/kvm/x86/kvm.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- linux-2.6.git.orig/tools/kvm/x86/kvm.c +++ linux-2.6.git/tools/kvm/x86/kvm.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include