mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: James Bottomley <jbottomley@parallels.com>
Cc: Christoph Hellwig <hch@infradead.org>,
	linux-scsi@vger.kernel.org, Robert Elliott <elliott@hp.com>,
	Hannes Reinecke <hare@suse.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH 29/38] Introduce dev_printk_string() and dev_printk_header()
Date: Mon, 29 Sep 2014 13:58:58 +0200	[thread overview]
Message-ID: <1411991947-130166-30-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1411991947-130166-1-git-send-email-hare@suse.de>

Introducing dev_printk_string() and dev_printk_header() to allow
using an external buffer for printing via dev_printk().

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>
Signed-off-by: Hannes Reinecke <hare@suse.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


  parent reply	other threads:[~2014-09-29 11:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1411991947-130166-1-git-send-email-hare@suse.de>
2014-09-29 11:58 ` [PATCH 27/38] Rearrange buffer formatting in printk() Hannes Reinecke
2014-09-30 16:16   ` Petr Mladek
2014-09-30 19:37     ` Petr Mladek
2014-09-29 11:58 ` [PATCH 28/38] Externalize string buffer for printk Hannes Reinecke
2014-09-30 16:39   ` Petr Mladek
2014-09-30 18:52     ` Hannes Reinecke
2014-09-29 11:58 ` Hannes Reinecke [this message]
2014-09-29 16:58   ` [PATCH 29/38] Introduce dev_printk_string() and dev_printk_header() Greg Kroah-Hartman
2014-09-30  5:48     ` Hannes Reinecke
2014-09-29 11:59 ` [PATCH 33/38] libata: use __scsi_print_command() Hannes Reinecke
2014-09-29 14:06   ` Tejun Heo
2014-09-29 14:10     ` Hannes Reinecke
2014-09-29 14:11       ` Tejun Heo

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=1411991947-130166-30-git-send-email-hare@suse.de \
    --to=hare@suse.de \
    --cc=elliott@hp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=jbottomley@parallels.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=rostedt@goodmis.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®