Make it possible to use _MASKED_FIELD(), _MASKED_BIT_ENABLE() and
_MASKED_BIT_DISABLE() in contexts that require integer constant
expressions. This increases their usefulness at the small cost of making
the warnings from build time checks less helpful.

Signed-off-by: Jani Nikula <[email protected]>
---
 drivers/gpu/drm/i915/i915_reg_defs.h | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_reg_defs.h 
b/drivers/gpu/drm/i915/i915_reg_defs.h
index e81fac8ab51b..c39b3a5dafe6 100644
--- a/drivers/gpu/drm/i915/i915_reg_defs.h
+++ b/drivers/gpu/drm/i915/i915_reg_defs.h
@@ -106,17 +106,17 @@
               BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), 
(~((__mask) >> __bf_shf(__mask)) & (__val)), 0))))
 
 #define __MASKED_FIELD(mask, value) ((mask) << 16 | (value))
-#define _MASKED_FIELD(mask, value) ({                                     \
-       if (__builtin_constant_p(mask))                                    \
-               BUILD_BUG_ON_MSG(((mask) & 0xffff0000), "Incorrect mask"); \
-       if (__builtin_constant_p(value))                                   \
-               BUILD_BUG_ON_MSG((value) & 0xffff0000, "Incorrect value"); \
-       if (__builtin_constant_p(mask) && __builtin_constant_p(value))     \
-               BUILD_BUG_ON_MSG((value) & ~(mask),                        \
-                                "Incorrect value for mask");              \
-       __MASKED_FIELD(mask, value); })
-#define _MASKED_BIT_ENABLE(a)  ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); })
-#define _MASKED_BIT_DISABLE(a) (_MASKED_FIELD((a), 0))
+#define _MASKED_FIELD(mask, value) \
+       (BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask), 
(mask) & 0xffff0000, 0)) + \
+        BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(value), 
(value) & 0xffff0000, 0)) + \
+        BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask) && 
__builtin_constant_p(value), (value) & ~(mask), 0)) + \
+        __MASKED_FIELD(mask, value))
+
+#define _MASKED_BIT_ENABLE(a) \
+       (__builtin_choose_expr(__builtin_constant_p(a), _MASKED_FIELD((a), 
(a)), ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); })))
+
+#define _MASKED_BIT_DISABLE(a) \
+       (_MASKED_FIELD((a), 0))
 
 /*
  * Given the first two numbers __a and __b of arbitrarily many evenly spaced
-- 
2.47.3

Reply via email to