From: Arjan van de Ven <arjan@infradead.org>
To: Arjan van de Ven <arjan@infradead.org>
Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org
Subject: [patch 2/3] Add a WARN() macro; this is WARN_ON() + printk arguments
Date: Tue, 6 May 2008 23:21:13 -0700 [thread overview]
Message-ID: <20080506232113.7f066c26@infradead.org> (raw)
In-Reply-To: <20080506232017.247001e0@infradead.org>
Subject: Add a WARN() macro; this is WARN_ON() + printk arguments
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>
---
include/asm-generic/bug.h | 16 ++++++++++++++++
kernel/panic.c | 24 ++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 2632328..dcefa5e 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -34,9 +34,13 @@ 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, ...);
#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 +52,18 @@ extern void warn_on_slowpath(const char *file, const int line);
})
#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()
diff --git a/kernel/panic.c b/kernel/panic.c
index 425567f..3e0c36b 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -318,6 +318,30 @@ void warn_on_slowpath(const char *file, int line)
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
--
1.5.4.5
next prev parent reply other threads:[~2008-05-07 6:21 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-07 6:20 [patch 1/3] Rename WARN() to WARNING() to clear the namespace Arjan van de Ven
2008-05-07 6:21 ` Arjan van de Ven [this message]
2008-05-07 6:21 ` [patch 3/3] Example use of WARN() Arjan van de Ven
2008-05-14 4:36 ` Andrew Morton
2008-05-14 4:51 ` Arjan van de Ven
2008-05-15 3:43 ` Arjan van de Ven
2008-05-07 6:41 ` [patch 2/3] Add a WARN() macro; this is WARN_ON() + printk arguments Vegard Nossum
2008-05-07 13:37 ` Arjan van de Ven
2008-05-07 7:31 ` Jiri Slaby
2008-05-07 12:46 ` [patch 1/3] Rename WARN() to WARNING() to clear the namespace Johannes Weiner
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=20080506232113.7f066c26@infradead.org \
--to=arjan@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®