[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1411991947-130166-30-git-send-email-hare@suse.de>
Date: Mon, 29 Sep 2014 13:58:58 +0200
From: Hannes Reinecke <hare@...e.de>
To: James Bottomley <jbottomley@...allels.com>
Cc: Christoph Hellwig <hch@...radead.org>, linux-scsi@...r.kernel.org,
Robert Elliott <elliott@...com>,
Hannes Reinecke <hare@...e.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Steven Rostedt <rostedt@...dmis.org>,
LKML <linux-kernel@...r.kernel.org>
Subject: [PATCH 29/38] Introduce dev_printk_string() and dev_printk_header()
Introducing dev_printk_string() and dev_printk_header() to allow
using an external buffer for printing via dev_printk().
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: LKML <linux-kernel@...r.kernel.org>
Signed-off-by: Hannes Reinecke <hare@...e.de>
---
drivers/base/core.c | 24 ++++++++++++++++++++++++
include/linux/device.h | 12 ++++++++++++
2 files changed, 36 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 20da3ad..e8aecf0 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -2041,6 +2041,19 @@ create_syslog_header(const struct device *dev, char *hdr, size_t hdrlen)
return pos;
}
+int dev_printk_string(int level, const struct device *dev,
+ char *msg, size_t msg_len)
+{
+ char hdr[128];
+ size_t hdrlen;
+
+ hdrlen = create_syslog_header(dev, hdr, sizeof(hdr));
+
+ return printk_emit_string(0, level, hdrlen ? hdr : NULL, hdrlen,
+ msg, msg_len);
+}
+EXPORT_SYMBOL(dev_printk_string);
+
int dev_vprintk_emit(int level, const struct device *dev,
const char *fmt, va_list args)
{
@@ -2068,6 +2081,17 @@ int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
}
EXPORT_SYMBOL(dev_printk_emit);
+int dev_printk_header(char *buf, size_t buf_len, const struct device *dev)
+{
+ size_t off = 0;
+
+ if (dev)
+ off = scnprintf(buf, buf_len, "%s %s: ",
+ dev_driver_string(dev), dev_name(dev));
+ return off;
+}
+EXPORT_SYMBOL(dev_printk_header);
+
static int __dev_printk(const char *level, const struct device *dev,
struct va_format *vaf)
{
diff --git a/include/linux/device.h b/include/linux/device.h
index 43d183a..47f3b62 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1025,6 +1025,9 @@ extern const char *dev_driver_string(const struct device *dev);
#ifdef CONFIG_PRINTK
+int dev_printk_string(int level, const struct device *dev,
+ char *msg, size_t msg_len);
+int dev_printk_header(char *buf, size_t buf_len, const struct device *dev);
extern __printf(3, 0)
int dev_vprintk_emit(int level, const struct device *dev,
const char *fmt, va_list args);
@@ -1051,6 +1054,15 @@ int _dev_info(const struct device *dev, const char *fmt, ...);
#else
+static inline
+int dev_printk_string(int level, const struct device *dev,
+ char *msg, size_t msg_len)
+{ return 0; }
+
+static inline
+int dev_printk_header(char *buf, size_t buf_len, const struct device *dev)
+{ return 0; }
+
static inline __printf(3, 0)
int dev_vprintk_emit(int level, const struct device *dev,
const char *fmt, va_list args)
--
1.8.5.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists