[Intel-gfx] [PATCH 1/6] drm/i915: Compile time concatenate WARN_ON macro strings

Joonas Lahtinen joonas.lahtinen at linux.intel.com
Thu Dec 17 11:25:46 PST 2015


Using __stringify(x) instead of #x adds support for macros as
a parameter and reduces runtime overhead.

Slightly increases the .text size but should not matter.

Cc: Rob Clark <robdclark at gmail.com>
Acked-by: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 1d28d90..fe3e76d 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -69,11 +69,11 @@
 		BUILD_BUG_ON(__i915_warn_cond); \
 	WARN(__i915_warn_cond, "WARN_ON(" #x ")"); })
 #else
-#define WARN_ON(x) WARN((x), "WARN_ON(%s)", #x )
+#define WARN_ON(x) WARN((x), "WARN_ON(" __stringify(x) ")")
 #endif
 
 #undef WARN_ON_ONCE
-#define WARN_ON_ONCE(x) WARN_ONCE((x), "WARN_ON_ONCE(%s)", #x )
+#define WARN_ON_ONCE(x) WARN_ONCE((x), "WARN_ON_ONCE(" __stringify(x) ")")
 
 #define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
 			     (long) (x), __func__);
@@ -97,12 +97,14 @@
 })
 
 #define I915_STATE_WARN_ON(condition) ({				\
+	static const char __warn_on_txt[] =				\
+		"WARN_ON(" __stringify(condition) ")\n";		\
 	int __ret_warn_on = !!(condition);				\
 	if (unlikely(__ret_warn_on)) {					\
 		if (i915.verbose_state_checks)				\
-			WARN(1, "WARN_ON(" #condition ")\n");		\
+			WARN(1, __warn_on_txt);				\
 		else 							\
-			DRM_ERROR("WARN_ON(" #condition ")\n");		\
+			DRM_ERROR(__warn_on_txt);			\
 	}								\
 	unlikely(__ret_warn_on);					\
 })
-- 
2.4.3



More information about the Intel-gfx mailing list