Commit 96928d90 authored by Sergey Senozhatsky's avatar Sergey Senozhatsky Committed by Steven Rostedt (Google)

seq_buf: Add seq_buf_do_printk() helper

Sometimes we use seq_buf to format a string buffer, which
we then pass to printk(). However, in certain situations
the seq_buf string buffer can get too big, exceeding the
PRINTKRB_RECORD_MAX bytes limit, and causing printk() to
truncate the string.

Add a new seq_buf helper. This helper prints the seq_buf
string buffer line by line, using \n as a delimiter,
rather than passing the whole string buffer to printk()
at once.

Link: https://lkml.kernel.org/r/20230415100110.1419872-1-senozhatsky@chromium.org

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarSergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: default avatarPetr Mladek <pmladek@suse.com>
Tested-by: default avatarYosry Ahmed <yosryahmed@google.com>
Signed-off-by: default avatarSteven Rostedt (Google) <rostedt@goodmis.org>
parent c7bdb079
...@@ -159,4 +159,6 @@ extern int ...@@ -159,4 +159,6 @@ extern int
seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary); seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
#endif #endif
void seq_buf_do_printk(struct seq_buf *s, const char *lvl);
#endif /* _LINUX_SEQ_BUF_H */ #endif /* _LINUX_SEQ_BUF_H */
...@@ -93,6 +93,38 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...) ...@@ -93,6 +93,38 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
} }
EXPORT_SYMBOL_GPL(seq_buf_printf); EXPORT_SYMBOL_GPL(seq_buf_printf);
/**
* seq_buf_do_printk - printk seq_buf line by line
* @s: seq_buf descriptor
* @lvl: printk level
*
* printk()-s a multi-line sequential buffer line by line. The function
* makes sure that the buffer in @s is nul terminated and safe to read
* as a string.
*/
void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
{
const char *start, *lf;
if (s->size == 0 || s->len == 0)
return;
seq_buf_terminate(s);
start = s->buffer;
while ((lf = strchr(start, '\n'))) {
int len = lf - start + 1;
printk("%s%.*s", lvl, len, start);
start = ++lf;
}
/* No trailing LF */
if (start < s->buffer + s->len)
printk("%s%s\n", lvl, start);
}
EXPORT_SYMBOL_GPL(seq_buf_do_printk);
#ifdef CONFIG_BINARY_PRINTF #ifdef CONFIG_BINARY_PRINTF
/** /**
* seq_buf_bprintf - Write the printf string from binary arguments * seq_buf_bprintf - Write the printf string from binary arguments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment