[Xen-devel,RFC,v4,1/8] Port WARN_ON_ONCE() from Linux

Message ID 20171219031703.23420-2-sameer.goel@linaro.org
State New
Headers show
Series
  • SMMUv3 driver
Related show

Commit Message

Sameer Goel Dec. 19, 2017, 3:16 a.m.
Port WARN_ON_ONCE macro from Linux.

Signed-off-by: Sameer Goel <sameer.goel@linaro.org>
---
 xen/include/xen/lib.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch

diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index ed00ae1379..83206c0848 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -11,6 +11,17 @@ 
 #define BUG_ON(p)  do { if (unlikely(p)) BUG();  } while (0)
 #define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
 
+#define WARN_ON_ONCE(p)	({                          \
+    static bool __section(".data.unlikely") __warned; \
+    int __ret_warn_once = !!(p);                    \
+                                                    \
+    if (unlikely(__ret_warn_once && !__warned)) {   \
+        __warned = true;                            \
+        WARN_ON(1);                                 \
+    }                                               \
+    unlikely(__ret_warn_once);                      \
+})
+
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
 /* Force a compilation error if condition is true */
 #define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })