[PATCH 3/5] virtio: Fix none-const BUILD_BUG_ON usage

From: Boaz Harrosh
Date: Mon Sep 01 2008 - 09:13:55 EST



BUILD_BUG_ON can not be used cross inline parametrization boundary.
I've put the BUILD_BUG_ON(_ZERO) in a macro outside of the inline
definition. (So it is in the caller scope).

NOTE to Rusty:
If I remove the "__builtin_constant_p ?" part then code compiles
just fine, because all call sights of virtio_has_feature() use
constants for fbit. But it seems like it was not intended to be
forced.

Signed-off-by: Boaz Harrosh <bharrosh@xxxxxxxxxxx>
CC: Ingo Molnar <mingo@xxxxxxx>
CC: Rusty Russell <rusty@xxxxxxxxxxxxxxx>
---
include/linux/virtio_config.h | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index bf8ec28..d9402d8 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -92,17 +92,19 @@ void virtio_check_driver_offered_feature(const struct virtio_device *vdev,
* @vdev: the device
* @fbit: the feature bit
*/
-static inline bool virtio_has_feature(const struct virtio_device *vdev,
+static inline bool __virtio_has_feature(const struct virtio_device *vdev,
unsigned int fbit)
{
- /* Did you forget to fix assumptions on max features? */
- if (__builtin_constant_p(fbit))
- BUILD_BUG_ON(fbit >= 32);
-
virtio_check_driver_offered_feature(vdev, fbit);
return test_bit(fbit, vdev->features);
}

+/* Did you forget to fix assumptions on max features? */
+#define virtio_has_feature(vdev, fbit) \
+ ((__builtin_constant_p(fbit) ? BUILD_BUG_ON_ZERO(fbit >= 32) : 0) + \
+ __virtio_has_feature(vdev, fbit))
+
+
/**
* virtio_config_val - look for a feature and get a virtio config entry.
* @vdev: the virtio device
--
1.5.6.rc1.5.gadf6


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/