From: Arjan van de Ven <arjan@infradead.org>
To: Arjan van de Ven <arjan@infradead.org>, linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, mingo@elte.hu
Subject: [patch 2/17] Add a WARN() macro that acts like WARN_ON()+printk
Date: Tue, 8 Jul 2008 09:40:23 -0700 [thread overview]
Message-ID: <20080708094023.260a31bb@infradead.org> (raw)
In-Reply-To: <20080708093800.274504ba@infradead.org>
From: Arjan van de Ven <arjan@linux.intel.com>
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.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/asm-generic/bug.h | 32 ++++++++++++++++++++++++++++++++
kernel/panic.c | 22 ++++++++++++++++++++++
2 files changed, 54 insertions(+)
Index: linux.trees.git/include/asm-generic/bug.h
===================================================================
--- linux.trees.git.orig/include/asm-generic/bug.h
+++ linux.trees.git/include/asm-generic/bug.h
@@ -34,9 +34,14 @@ struct bug_entry {
#ifndef __WARN
#ifndef __ASSEMBLY__
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
#endif
#define __WARN() warn_on_slowpath(__FILE__, __LINE__)
+#define __WARN_printf(arg...) warn_slowpath(__FILE__, __LINE__, arg)
+#else
+#define __WARN_printf(arg...) __WARN()
#endif
#ifndef WARN_ON
@@ -48,6 +53,15 @@ extern void warn_on_slowpath(const char
})
#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 */
#ifndef HAVE_ARCH_BUG
#define BUG()
@@ -63,6 +77,14 @@ extern void warn_on_slowpath(const char
unlikely(__ret_warn_on); \
})
#endif
+
+#ifndef WARN
+#define WARN(condition, format...) ({ \
+ int __ret_warn_on = !!(condition); \
+ unlikely(__ret_warn_on); \
+})
+#endif
+
#endif
#define WARN_ON_ONCE(condition) ({ \
@@ -75,6 +97,16 @@ extern void warn_on_slowpath(const char
unlikely(__ret_warn_once); \
})
+#define WARN_ONCE(condition, format...) ({ \
+ static int __warned; \
+ int __ret_warn_once = !!(condition); \
+ \
+ if (unlikely(__ret_warn_once)) \
+ if (WARN(!__warned, format)) \
+ __warned = 1; \
+ unlikely(__ret_warn_once); \
+})
+
#ifdef CONFIG_SMP
# define WARN_ON_SMP(x) WARN_ON(x)
#else
Index: linux.trees.git/kernel/panic.c
===================================================================
--- linux.trees.git.orig/kernel/panic.c
+++ linux.trees.git/kernel/panic.c
@@ -321,6 +321,28 @@ void warn_on_slowpath(const char *file,
add_taint(TAINT_WARN);
}
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
#ifdef CONFIG_CC_STACKPROTECTOR
next prev parent reply other threads:[~2008-07-08 17:02 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-08 16:38 [patch 0/17] Series to introduce WARN()... a WARN_ON() variant that takes printk arguments Arjan van de Ven
2008-07-08 16:39 ` [patch 1/17] Clear the WARN() namespace Arjan van de Ven
2008-07-11 19:19 ` Andrew Morton
2008-07-08 16:40 ` Arjan van de Ven [this message]
2008-07-08 18:00 ` [patch 2/17] Add a WARN() macro that acts like WARN_ON()+printk Joe Perches
2008-07-08 18:18 ` Arjan van de Ven
2008-07-11 19:19 ` Andrew Morton
2008-07-11 20:51 ` Arjan van de Ven
2008-07-08 16:41 ` [patch 3/17] Introduce WARN() usage in the kobject code Arjan van de Ven
2008-07-08 16:42 ` [patch 4/17] Use WARN() in kernel/irq/manage.c Arjan van de Ven
2008-07-08 16:45 ` [patch 5/17] Use WARN() in kernel/panic.c Arjan van de Ven
2008-07-08 16:46 ` [patch 6/17] Use WARN() in mm/vmalloc.c Arjan van de Ven
2008-07-08 16:47 ` [patch 7/17] use WARN() in kernel/lockdep.c Arjan van de Ven
2008-07-08 16:48 ` [patch 8/17] use WARN() in kernel/irq/chip.c Arjan van de Ven
2008-07-08 16:50 ` [patch 9/17] Use WARN() in arch/x86/mm/ioremap.c Arjan van de Ven
2008-07-08 16:51 ` [patch 10/17] use WARN() in arch/x86/mm/pageattr.c Arjan van de Ven
2008-07-08 16:51 ` [patch 11/17] Use WARN() in arch/x86/kernel Arjan van de Ven
2008-07-08 16:52 ` [patch 12/17] Use WARN() in block/ Arjan van de Ven
2008-07-08 16:53 ` [patch 13/17] Use WARN() in drivers/base/ Arjan van de Ven
2008-07-11 19:20 ` Andrew Morton
2008-07-11 20:54 ` Arjan van de Ven
2008-07-11 22:11 ` Andrew Morton
2008-07-11 22:35 ` Arjan van de Ven
2008-07-11 22:51 ` Arjan van de Ven
2008-07-11 23:02 ` Andrew Morton
2008-07-11 23:56 ` Arjan van de Ven
2008-07-11 23:10 ` Johannes Berg
2008-07-12 0:51 ` Johannes Berg
2008-07-08 16:53 ` [patch 14/17] Use WARN() in lib/ Arjan van de Ven
2008-07-08 16:54 ` [patch 15/17] Use WARN() in fs/ Arjan van de Ven
2008-07-08 16:54 ` Arjan van de Ven
2008-07-08 16:55 ` Arjan van de Ven
2008-07-08 16:56 ` [patch 16/17] Usr WARN() in fs/sysfs Arjan van de Ven
2008-07-08 16:57 ` [patch 17/17] Use WARN() in fs/proc/ Arjan van de Ven
2008-07-09 10:13 ` [patch 0/17] Series to introduce WARN()... a WARN_ON() variant that takes printk arguments Ingo Molnar
2008-07-09 11:19 ` Andrew Morton
2008-07-09 11:37 ` Ingo Molnar
2008-07-09 11:46 ` Andrew Morton
2008-07-09 12:13 ` Ingo Molnar
2008-07-09 13:31 ` Arjan van de Ven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080708094023.260a31bb@infradead.org \
--to=arjan@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox