[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] xen: let ASSERT_UNREACHABLE() WARN() in non-debug builds



Hitting an ASSERT_UNREACHABLE() is always wrong, so even in production
builds a warning seems to be appropriate when hitting one.

In order not to flood the console in reproducible cases, introduce
WARN_ONCE() to be used in this case.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
Notice for the release manager: this patch isn't really urgent for the
4.17 release, OTOH it is adding probably useful debug information for
the unlikely case of hitting an ASSERT_UNREACHABLE(). The risk for
taking the patch should be rather low, but you have the last saying,
of course.

Signed-off-by: Juergen Gross <jgross@xxxxxxxx>
---
 xen/include/xen/lib.h | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 05ee1e18af..b8472d753c 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -40,6 +40,16 @@
     unlikely(ret_warn_on_);             \
 })
 
+#define WARN_ONCE() do {                \
+    static bool warned = false;         \
+                                        \
+    if ( !warned )                      \
+    {                                   \
+        warned = true;                  \
+        WARN();                         \
+    }                                   \
+} while (0)
+
 /* All clang versions supported by Xen have _Static_assert. */
 #if defined(__clang__) || \
     (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
@@ -63,7 +73,7 @@
 #define ASSERT_UNREACHABLE() assert_failed("unreachable")
 #else
 #define ASSERT(p) do { if ( 0 && (p) ) {} } while (0)
-#define ASSERT_UNREACHABLE() do { } while (0)
+#define ASSERT_UNREACHABLE() WARN_ONCE()
 #endif
 
 #define ABS(_x) ({                              \
-- 
2.35.3




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.