From: Julien Grall Date: Fri, 18 Dec 2020 13:30:54 +0000 (+0000) Subject: xen: Rework WARN_ON() to return whether a warning was triggered X-Git-Tag: archive/raspbian/4.16.0+51-g0941d6cb-1+rpi1~2^2~42^2~1234 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8c8938dcc1bd37dd61f705410053e08804ca2b55;p=xen.git xen: Rework WARN_ON() to return whether a warning was triggered So far, our implementation of WARN_ON() cannot be used in the following situation: if ( WARN_ON() ) ... This is because WARN_ON() doesn't return whether a warning has been triggered. Such construciton can be handy if you want to print more information and also dump the stack trace. Therefore, rework the WARN_ON() implementation to return whether a warning was triggered. The idea was borrowed from Linux Signed-off-by: Julien Grall Reviewed-by: Juergen Gross Reviewed-by: Bertrand Marquis Acked-by: Stefano Stabellini Acked-by: Jan Beulich --- diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 48429b69b8..5841bd489c 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -23,7 +23,13 @@ #include #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(p) ({ \ + bool ret_warn_on_ = (p); \ + \ + if ( unlikely(ret_warn_on_) ) \ + WARN(); \ + unlikely(ret_warn_on_); \ +}) /* All clang versions supported by Xen have _Static_assert. */ #if defined(__clang__) || \