Commit a8f18b90 authored by Arjan van de Ven's avatar Arjan van de Ven Committed by Linus Torvalds

Add a WARN() macro; this is WARN_ON() + printk arguments

Add a WARN() macro that acts like WARN_ON(), with the added feature that it
takes a printk like argument that is printed as part of the warning message.

[akpm@linux-foundation.org: fix printk arguments]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: default avatarArjan van de Ven <arjan@linux.intel.com>
Cc: Greg KH <greg@kroah.com>
Cc: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b6c63937
...@@ -34,9 +34,14 @@ struct bug_entry { ...@@ -34,9 +34,14 @@ struct bug_entry {
#ifndef __WARN #ifndef __WARN
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
extern void warn_on_slowpath(const char *file, const int line); extern void warn_on_slowpath(const char *file, const int line);
extern void warn_slowpath(const char *file, const int line,
const char *fmt, ...) __attribute__((format(printf, 3, 4)));
#define WANT_WARN_ON_SLOWPATH #define WANT_WARN_ON_SLOWPATH
#endif #endif
#define __WARN() warn_on_slowpath(__FILE__, __LINE__) #define __WARN() warn_on_slowpath(__FILE__, __LINE__)
#define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
#else
#define __WARN_printf(arg...) __WARN()
#endif #endif
#ifndef WARN_ON #ifndef WARN_ON
...@@ -48,6 +53,15 @@ extern void warn_on_slowpath(const char *file, const int line); ...@@ -48,6 +53,15 @@ extern void warn_on_slowpath(const char *file, const int line);
}) })
#endif #endif
#ifndef WARN
#define WARN(condition, format...) ({ \
int __ret_warn_on = !!(condition); \
if (unlikely(__ret_warn_on)) \
__WARN_printf(format); \
unlikely(__ret_warn_on); \
})
#endif
#else /* !CONFIG_BUG */ #else /* !CONFIG_BUG */
#ifndef HAVE_ARCH_BUG #ifndef HAVE_ARCH_BUG
#define BUG() #define BUG()
...@@ -63,6 +77,14 @@ extern void warn_on_slowpath(const char *file, const int line); ...@@ -63,6 +77,14 @@ extern void warn_on_slowpath(const char *file, const int line);
unlikely(__ret_warn_on); \ unlikely(__ret_warn_on); \
}) })
#endif #endif
#ifndef WARN
#define WARN(condition, format...) ({ \
int __ret_warn_on = !!(condition); \
unlikely(__ret_warn_on); \
})
#endif
#endif #endif
#define WARN_ON_ONCE(condition) ({ \ #define WARN_ON_ONCE(condition) ({ \
......
...@@ -318,6 +318,28 @@ void warn_on_slowpath(const char *file, int line) ...@@ -318,6 +318,28 @@ void warn_on_slowpath(const char *file, int line)
add_taint(TAINT_WARN); add_taint(TAINT_WARN);
} }
EXPORT_SYMBOL(warn_on_slowpath); EXPORT_SYMBOL(warn_on_slowpath);
void warn_slowpath(const char *file, int line, const char *fmt, ...)
{
va_list args;
char function[KSYM_SYMBOL_LEN];
unsigned long caller = (unsigned long)__builtin_return_address(0);
sprint_symbol(function, caller);
printk(KERN_WARNING "------------[ cut here ]------------\n");
printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file,
line, function);
va_start(args, fmt);
vprintk(fmt, args);
va_end(args);
print_modules();
dump_stack();
print_oops_end_marker();
add_taint(TAINT_WARN);
}
EXPORT_SYMBOL(warn_slowpath);
#endif #endif
#ifdef CONFIG_CC_STACKPROTECTOR #ifdef CONFIG_CC_STACKPROTECTOR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment