diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-08 14:41:43 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2019-03-08 14:41:43 -0500 |
commit | 166e32606ef3508517ed2ea2f6087e5f332981c1 (patch) | |
tree | f81c218c603282dbb41918958efc7c4f6608b0aa | |
parent | fd67296247e3404a9843cc5f4226632f0fdd55ad (diff) |
better implementation of WARN
-rw-r--r-- | include/linux/bug.h | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/include/linux/bug.h b/include/linux/bug.h index f8929688..a64a309c 100644 --- a/include/linux/bug.h +++ b/include/linux/bug.h @@ -9,22 +9,46 @@ #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#define BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2*!!(cond)])) #define BUG() do { assert(0); unreachable(); } while (0) #define BUG_ON(cond) assert(!(cond)) -#define WARN_ON_ONCE(cond) ({ bool _r = (cond); if (_r) assert(0); _r; }) -#define WARN_ONCE(cond, ...) ({ bool _r = (cond); if (_r) assert(0); _r; }) - -#define __WARN() assert(0) -#define __WARN_printf(arg...) assert(0) -#define WARN(cond, ...) assert(!(cond)) +#define WARN(cond, fmt, ...) \ +({ \ + int __ret_warn_on = unlikely(!!(cond)); \ + if (__ret_warn_on) \ + fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\ + __LINE__, ##__VA_ARGS__); \ + __ret_warn_on; \ +}) -#define WARN_ON(condition) ({ \ - int __ret_warn_on = unlikely(!!(condition)); \ +#define WARN_ON(cond) ({ \ + int __ret_warn_on = unlikely(!!(cond)); \ if (__ret_warn_on) \ - __WARN(); \ + fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__);\ + __ret_warn_on; \ +}) + +#define WARN_ONCE(cond, fmt, ...) \ +({ \ + static bool __warned; \ + int __ret_warn_on = unlikely(!!(cond)); \ + if (__ret_warn_on && !__warned) { \ + __warned = true; \ + fprintf(stderr, "WARNING at " __FILE__ ":%d: " fmt "\n",\ + __LINE__, ##__VA_ARGS__); \ + } \ + __ret_warn_on; \ +}) + +#define WARN_ON_ONCE(cond) ({ \ + static bool __warned; \ + int __ret_warn_on = unlikely(!!(cond)); \ + if (__ret_warn_on && !__warned) { \ + __warned = true; \ + fprintf(stderr, "WARNING at " __FILE__ ":%d\n", __LINE__);\ + } \ __ret_warn_on; \ }) |