From: Petr Mladek <pmladek@suse.com>
To: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Andrew Morton <akpm@linux-foundation.org>,
Yosry Ahmed <yosryahmed@google.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] seq_buf: add seq_buf_printk() helper
Date: Tue, 11 Apr 2023 14:14:30 +0200 [thread overview]
Message-ID: <ZDVPJnx9tjetdm9K@alley> (raw)
In-Reply-To: <20230411025556.751349-1-senozhatsky@chromium.org>
On Tue 2023-04-11 11:55:56, Sergey Senozhatsky wrote:
> 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.
>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
> include/linux/seq_buf.h | 2 ++
> lib/seq_buf.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> diff --git a/include/linux/seq_buf.h b/include/linux/seq_buf.h
> index 5b31c5147969..80b78df89809 100644
> --- a/include/linux/seq_buf.h
> +++ b/include/linux/seq_buf.h
> @@ -159,4 +159,6 @@ extern int
> seq_buf_bprintf(struct seq_buf *s, const char *fmt, const u32 *binary);
> #endif
>
> +void seq_buf_printk(struct seq_buf *s, const char *lvl);
> +
> #endif /* _LINUX_SEQ_BUF_H */
> diff --git a/lib/seq_buf.c b/lib/seq_buf.c
> index 0a68f7aa85d6..9d13004c2324 100644
> --- a/lib/seq_buf.c
> +++ b/lib/seq_buf.c
> @@ -93,6 +93,36 @@ int seq_buf_printf(struct seq_buf *s, const char *fmt, ...)
> }
> EXPORT_SYMBOL_GPL(seq_buf_printf);
>
> +/**
> + * seq_buf_printk - printk seq_buf line by line
> + * @s: seq_buf descriptor
> + * @lvl: printk level
> + *
> + * printk()-s a multi-line sequential buffer line by line
> + */
> +void seq_buf_printk(struct seq_buf *s, const char *lvl)
We might want to somehow distinguish that this is actually
printing (reading) the context of the buffer.
The name is similar to seq_buf_printf() and seq_buf_vprintf()
whose are wrinting into the buffer.
What about the following?
+ seq_buf_printf_seq() like the existing seq_buf_print_seq()
+ seq_buf_to_printk() like the existing seq_buf_to_user()
I personally prefer seq_buf_to_printk() because it looks more
selfexplaining to me.
Or maybe: seq_buf_to_printk_lvl() to allow later add
seq_buf_to_printk() that would us the default loglevel.
> +{
> + const char *start, *lf;
> + int len;
> +
> + if (s->size == 0)
> + return;
> +
> + start = s->buffer;
> + while ((lf = strchr(start, '\n'))) {
We should rather use strnchr(). It seems that the trailing '\0' is
not guaranteed. For example, seq_buf_putc() just adds the given
character at the end.
> + len = lf - start + 1;
> + printk("%s%.*s", lvl, len, start);
> + start = ++lf;
> + }
> +
> + /* No trailing LF */
> + if (start < s->buffer + s->len) {
> + len = s->buffer + s->len - start;
> + printk("%s%.*s\n", lvl, len, start);
> + }
> +}
> +EXPORT_SYMBOL_GPL(seq_buf_printk);
Otherwise, it looks good to me.
Best Regards,
Petr
next prev parent reply other threads:[~2023-04-11 12:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-11 2:55 Sergey Senozhatsky
2023-04-11 3:45 ` Yosry Ahmed
2023-04-11 12:14 ` Petr Mladek [this message]
2023-04-11 14:10 ` Steven Rostedt
2023-04-11 14:27 ` Sergey Senozhatsky
2023-04-11 14:24 ` Sergey Senozhatsky
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=ZDVPJnx9tjetdm9K@alley \
--to=pmladek@suse.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=yosryahmed@google.com \
/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®