xen: Rework WARN_ON() to return whether a warning was triggered
PATCH v2 1/1 xen: Rework WARN_ON() to return whether a warning was triggered
From: Julien Grall <[email protected]>
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
---
Changes in v2:
- Rework the commit message
- Don't use trailing underscore
- Add Bertrand's and Juergen's reviewed-by
--- xen/include/xen/lib.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
xen/include/xen/lib.h +7 -1
@@ -23,7 +23,13 @@#include <asm/bug.h> #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__) || \
Signature · 1 line
2.17.1
Quoted 12 lines · Julien Grall
From: Julien Grall <[email protected]>
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.
Quoted 6 lines
Therefore, rework the
WARN_ON()implementation to return whether a warning was triggered. The idea was borrowed from LinuxSigned-off-by Julien Grall <[email protected]>Reviewed-by Juergen Gross <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
Quoted 31 lines
---
Changes in v2:
- Rework the commit message
- Don't use trailing underscore
- Add Bertrand's and Juergen's reviewed-by--- xen/include/xen/lib.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)xen/include/xen/lib.h +7
-1@@ -23,7 +23,13 @@#include <asm/bug.h> #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__) || \Signature · 1 line
2.17.1
Quoted 12 lines · Julien Grall
From: Julien Grall <[email protected]>
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.
Quoted 6 lines
Therefore, rework the
WARN_ON()implementation to return whether a warning was triggered. The idea was borrowed from LinuxSigned-off-by Julien Grall <[email protected]>Reviewed-by Juergen Gross <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
In particular to clarify my prior concerns have been addressed:
Jan