[tip:tools/kvm] kvm tools: Add BUG_ON() helper to make a run-time critical tests

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  88284993aa743c0cbea86d66d2ba2b877b5763be
Gitweb:     http://git.kernel.org/tip/88284993aa743c0cbea86d66d2ba2b877b5763be
Author:     Cyrill Gorcunov <gorcunov@xxxxxxxxx>
AuthorDate: Mon, 19 Dec 2011 12:25:45 +0400
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Mon, 19 Dec 2011 19:39:04 +0200

kvm tools: Add BUG_ON() helper to make a run-time critical tests

Also drop useless assert.h inclusions.

Acked-by: Ingo Molnar <mingo@xxxxxxx>
Signed-off-by: Cyrill Gorcunov <gorcunov@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 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(-)

diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index 83088af..2792c88 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -9,6 +9,7 @@
  * Some bits are stolen from perf tool :)
  */
 
+#include <assert.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stddef.h>
@@ -50,7 +51,9 @@ extern void set_die_routine(void (*routine)(const char *err, va_list params) NOR
 				__func__, __LINE__, ##__VA_ARGS__);	\
 	} while (0)
 
-#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))
 
 #define DIE_IF(cnd)						\
 do {								\
diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index b417942..5a5a331 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -10,7 +10,6 @@
 #include <linux/types.h>
 
 #include <stdbool.h>
-#include <assert.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/tools/kvm/kvm-cmd.c b/tools/kvm/kvm-cmd.c
index 604dce4..2520b08 100644
--- a/tools/kvm/kvm-cmd.c
+++ b/tools/kvm/kvm-cmd.c
@@ -2,8 +2,6 @@
 #include <string.h>
 #include <errno.h>
 
-#include <assert.h>
-
 /* user defined header files */
 #include "kvm/builtin-debug.h"
 #include "kvm/builtin-pause.h"
@@ -71,14 +69,14 @@ int handle_command(struct cmd_struct *command, int argc, const char **argv)
 
 	if (!argv || !*argv) {
 		p = kvm_get_command(command, "help");
-		assert(p);
+		BUG_ON(!p);
 		return p->fn(argc, argv, prefix);
 	}
 
 	p = kvm_get_command(command, argv[0]);
 	if (!p) {
 		p = kvm_get_command(command, "help");
-		assert(p);
+		BUG_ON(!p);
 		p->fn(0, NULL, prefix);
 		return EINVAL;
 	}
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index 8c9e268..a60b11d 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -14,7 +14,6 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <stdbool.h>
-#include <assert.h>
 #include <limits.h>
 #include <signal.h>
 #include <stdarg.h>
diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c
index 06eea0f..41c4085 100644
--- a/tools/kvm/pci.c
+++ b/tools/kvm/pci.c
@@ -3,8 +3,6 @@
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 
-#include <assert.h>
-
 #define PCI_BAR_OFFSET(b)		(offsetof(struct pci_device_header, bar[b]))
 
 static struct pci_device_header		*pci_devices[PCI_MAX_DEVICES];
@@ -170,13 +168,13 @@ void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data,
 
 void pci__register(struct pci_device_header *dev, u8 dev_num)
 {
-	assert(dev_num < PCI_MAX_DEVICES);
+	BUG_ON(dev_num >= PCI_MAX_DEVICES);
 	pci_devices[dev_num]	= dev;
 }
 
 struct pci_device_header *pci__find_dev(u8 dev_num)
 {
-	assert(dev_num < PCI_MAX_DEVICES);
+	BUG_ON(dev_num >= PCI_MAX_DEVICES);
 	return pci_devices[dev_num];
 }
 
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index f838a8f..d107de6 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -17,7 +17,6 @@
 #include <sys/ioctl.h>
 #include <sys/mman.h>
 #include <stdbool.h>
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
diff --git a/tools/kvm/virtio/console.c b/tools/kvm/virtio/console.c
index 68c30f5..245cebb 100644
--- a/tools/kvm/virtio/console.c
+++ b/tools/kvm/virtio/console.c
@@ -21,7 +21,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <termios.h>
-#include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
 
@@ -136,7 +135,7 @@ static int init_vq(struct kvm *kvm, void *dev, u32 vq, u32 pfn)
 	struct virt_queue *queue;
 	void *p;
 
-	assert(vq < VIRTIO_CONSOLE_NUM_QUEUES);
+	BUG_ON(vq >= VIRTIO_CONSOLE_NUM_QUEUES);
 
 	compat__remove_message(compat_id);
 
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index bb97a7e..5e29708 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -19,7 +19,6 @@
 #include <net/if.h>
 
 #include <unistd.h>
-#include <assert.h>
 #include <fcntl.h>
 
 #include <sys/socket.h>
diff --git a/tools/kvm/x86/bios.c b/tools/kvm/x86/bios.c
index ded0717..0d1b1e3 100644
--- a/tools/kvm/x86/bios.c
+++ b/tools/kvm/x86/bios.c
@@ -98,7 +98,7 @@ static void e820_setup(struct kvm *kvm)
 		};
 	}
 
-	BUILD_BUG_ON(i > E820_X_MAX);
+	BUG_ON(i > E820_X_MAX);
 
 	e820->nr_map = i;
 }
diff --git a/tools/kvm/x86/cpuid.c b/tools/kvm/x86/cpuid.c
index 644f37f..75f3b4d 100644
--- a/tools/kvm/x86/cpuid.c
+++ b/tools/kvm/x86/cpuid.c
@@ -5,7 +5,6 @@
 
 #include <sys/ioctl.h>
 #include <stdlib.h>
-#include <assert.h>
 
 #define CPUID_FUNC_PERFMON		0x0A
 
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index d2fbbe2..129c4ff 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -15,7 +15,6 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <stdbool.h>
-#include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux