diff options
author | David Sterba <dsterba@suse.com> | 2016-10-04 18:55:09 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2016-10-05 12:39:01 +0200 |
commit | 26619538da1734250f42cf8eff13fe2c3a291dd7 (patch) | |
tree | 90302389c2f6ecfca7b10437c198455957077411 | |
parent | a08ca376f7746b4ec5839bacc4d7d7468a271dac (diff) |
btrfs-progs: kerncompat: make WARN_ON more verbose
Curretnly WARN_ON would crash but that's not it's purpose. Add helper
that prints the warning, optionally with trace.
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | kerncompat.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/kerncompat.h b/kerncompat.h index d2780dc2..26d3cb7e 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -94,6 +94,24 @@ static inline void assert_trace(const char *assertion, const char *filename, exit(1); } +static inline void warning_trace(const char *assertion, const char *filename, + const char *func, unsigned line, int val, + int trace) +{ + if (val) + return; + if (assertion) + fprintf(stderr, + "%s:%d: %s: Warning: assertion `%s` failed, value %d\n", + filename, line, func, assertion, val); + else + fprintf(stderr, + "%s:%d: %s: Warning: assertion failed, value %d.\n", + filename, line, func, val); + if (trace) + print_trace(); +} + #define BUG() assert_trace(NULL, __FILE__, __func__, __LINE__, 0) #else #define BUG() assert(0) @@ -270,12 +288,12 @@ static inline long IS_ERR(const void *ptr) #ifndef BTRFS_DISABLE_BACKTRACE #define BUG_ON(c) assert_trace(#c, __FILE__, __func__, __LINE__, !(c)) +#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 1) #else #define BUG_ON(c) assert(!(c)) +#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, !(c), 0) #endif -#define WARN_ON(c) BUG_ON(c) - #ifndef BTRFS_DISABLE_BACKTRACE #define ASSERT(c) assert_trace(#c, __FILE__, __func__, __LINE__, (c)) #else |