Introducing dev_printk_string() and dev_printk_header() to allow using an external buffer for printing via dev_printk().
Cc: Greg Kroah-Hartman <gre...@linuxfoundation.org> Cc: Steven Rostedt <rost...@goodmis.org> Cc: LKML <linux-ker...@vger.kernel.org> Signed-off-by: Hannes Reinecke <h...@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 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html