diff options
author | Jan Beulich <JBeulich@novell.com> | 2009-09-22 19:43:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-23 10:39:29 -0400 |
commit | 8c87df457cb58fe75b9b893007917cf8095660a0 (patch) | |
tree | 32446b329e4b83ae6158fa1505c36634a75dbfe8 /include/linux | |
parent | 1fe72eaa0f46a0fa4cdcd8f3f7853b6d39469784 (diff) |
BUILD_BUG_ON(): fix it and a couple of bogus uses of it
gcc permitting variable length arrays makes the current construct used for
BUILD_BUG_ON() useless, as that doesn't produce any diagnostic if the
controlling expression isn't really constant. Instead, this patch makes
it so that a bit field gets used here. Consequently, those uses where the
condition isn't really constant now also need fixing.
Note that in the gfp.h, kmemcheck.h, and virtio_config.h cases
MAYBE_BUILD_BUG_ON() really just serves documentation purposes - even if
the expression is compile time constant (__builtin_constant_p() yields
true), the array is still deemed of variable length by gcc, and hence the
whole expression doesn't have the intended effect.
[akpm@linux-foundation.org: make arch/sparc/include/asm/vio.h compile]
[akpm@linux-foundation.org: more nonsensical assertions in tpm.c..]
Signed-off-by: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
Cc: Mimi Zohar <zohar@us.ibm.com>
Cc: James Morris <jmorris@namei.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/gfp.h | 2 | ||||
-rw-r--r-- | include/linux/kernel.h | 8 | ||||
-rw-r--r-- | include/linux/kmemcheck.h | 2 | ||||
-rw-r--r-- | include/linux/virtio_config.h | 3 |
4 files changed, 9 insertions, 6 deletions
diff --git a/include/linux/gfp.h b/include/linux/gfp.h index f53e9b868c26..557bdad320b6 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h | |||
@@ -220,7 +220,7 @@ static inline enum zone_type gfp_zone(gfp_t flags) | |||
220 | ((1 << ZONES_SHIFT) - 1); | 220 | ((1 << ZONES_SHIFT) - 1); |
221 | 221 | ||
222 | if (__builtin_constant_p(bit)) | 222 | if (__builtin_constant_p(bit)) |
223 | BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1); | 223 | MAYBE_BUILD_BUG_ON((GFP_ZONE_BAD >> bit) & 1); |
224 | else { | 224 | else { |
225 | #ifdef CONFIG_DEBUG_VM | 225 | #ifdef CONFIG_DEBUG_VM |
226 | BUG_ON((GFP_ZONE_BAD >> bit) & 1); | 226 | BUG_ON((GFP_ZONE_BAD >> bit) & 1); |
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 55723afa097b..63dcaece1ac5 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -678,13 +678,17 @@ struct sysinfo { | |||
678 | }; | 678 | }; |
679 | 679 | ||
680 | /* Force a compilation error if condition is true */ | 680 | /* Force a compilation error if condition is true */ |
681 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) | 681 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) |
682 | |||
683 | /* Force a compilation error if condition is constant and true */ | ||
684 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) | ||
682 | 685 | ||
683 | /* Force a compilation error if condition is true, but also produce a | 686 | /* Force a compilation error if condition is true, but also produce a |
684 | result (of value 0 and type size_t), so the expression can be used | 687 | result (of value 0 and type size_t), so the expression can be used |
685 | e.g. in a structure initializer (or where-ever else comma expressions | 688 | e.g. in a structure initializer (or where-ever else comma expressions |
686 | aren't permitted). */ | 689 | aren't permitted). */ |
687 | #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1) | 690 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
691 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | ||
688 | 692 | ||
689 | /* Trap pasters of __FUNCTION__ at compile-time */ | 693 | /* Trap pasters of __FUNCTION__ at compile-time */ |
690 | #define __FUNCTION__ (__func__) | 694 | #define __FUNCTION__ (__func__) |
diff --git a/include/linux/kmemcheck.h b/include/linux/kmemcheck.h index 136cdcdf92ef..e880d4cf9e22 100644 --- a/include/linux/kmemcheck.h +++ b/include/linux/kmemcheck.h | |||
@@ -152,7 +152,7 @@ static inline bool kmemcheck_is_obj_initialized(unsigned long addr, size_t size) | |||
152 | \ | 152 | \ |
153 | _n = (long) &((ptr)->name##_end) \ | 153 | _n = (long) &((ptr)->name##_end) \ |
154 | - (long) &((ptr)->name##_begin); \ | 154 | - (long) &((ptr)->name##_begin); \ |
155 | BUILD_BUG_ON(_n < 0); \ | 155 | MAYBE_BUILD_BUG_ON(_n < 0); \ |
156 | \ | 156 | \ |
157 | kmemcheck_mark_initialized(&((ptr)->name##_begin), _n); \ | 157 | kmemcheck_mark_initialized(&((ptr)->name##_begin), _n); \ |
158 | } while (0) | 158 | } while (0) |
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index e547e3c8ee9a..0093dd7c1d6f 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
@@ -109,8 +109,7 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev, | |||
109 | unsigned int fbit) | 109 | unsigned int fbit) |
110 | { | 110 | { |
111 | /* Did you forget to fix assumptions on max features? */ | 111 | /* Did you forget to fix assumptions on max features? */ |
112 | if (__builtin_constant_p(fbit)) | 112 | MAYBE_BUILD_BUG_ON(fbit >= 32); |
113 | BUILD_BUG_ON(fbit >= 32); | ||
114 | 113 | ||
115 | if (fbit < VIRTIO_TRANSPORT_F_START) | 114 | if (fbit < VIRTIO_TRANSPORT_F_START) |
116 | virtio_check_driver_offered_feature(vdev, fbit); | 115 | virtio_check_driver_offered_feature(vdev, fbit); |