drm/i915: Compile-time concatenate WARN_ON macro strings
authorJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Fri, 18 Dec 2015 12:27:27 +0000 (14:27 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Tue, 22 Dec 2015 09:03:06 +0000 (10:03 +0100)
Using __stringify(x) instead of #x adds support for macros as
a parameter and compile-time concatenation reduces the runtime
overhead.

Slightly increases the .text size but should not matter.

v2:
- Define I915_STATE_WARN_ON though I915_STATE_WARN
  (Bikeshed inspiration by Chris)

v3:
- More specific commit message

v4:
- Do not directly pass arbitary string as format, instead
  guard with "%s" (Dave)

Cc: Rob Clark <robdclark@gmail.com>
Cc: Dave Gordon <david.s.gordon@intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> (v3)
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/1450441647-23924-3-git-send-email-joonas.lahtinen@linux.intel.com
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
drivers/gpu/drm/i915/i915_drv.h

index e0782b0fed73261134f0fbe924e70d3bae62df22..1d8279c220b4a043a1727b8d115b30dd3fb5ae77 100644 (file)
                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), "%s", "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), "%s", "WARN_ON_ONCE(" __stringify(x) ")")
 
 #define MISSING_CASE(x) WARN(1, "Missing switch case (%lu) in %s\n", \
                             (long) (x), __func__);
        unlikely(__ret_warn_on);                                        \
 })
 
-#define I915_STATE_WARN_ON(condition) ({                               \
-       int __ret_warn_on = !!(condition);                              \
-       if (unlikely(__ret_warn_on))                                    \
-               if (!WARN(i915.verbose_state_checks,                    \
-                         "WARN_ON(" #condition ")\n"))                 \
-                       DRM_ERROR("WARN_ON(" #condition ")\n");         \
-       unlikely(__ret_warn_on);                                        \
-})
+#define I915_STATE_WARN_ON(x)                                          \
+       I915_STATE_WARN((x), "%s", "WARN_ON(" __stringify(x) ")")
 
 static inline const char *yesno(bool v)
 {