From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org, yosryahmed@google.com,
rostedt@goodmis.org, pmladek@suse.com, senozhatsky@chromium.org,
akpm@linux-foundation.org
Subject: + seq_buf-add-seq_buf_do_printk-helper.patch added to mm-unstable branch
Date: Tue, 02 May 2023 19:17:37 -0700 [thread overview]
Message-ID: <20230503021738.0C358C433D2@smtp.kernel.org> (raw)
The patch titled
Subject: seq_buf: add seq_buf_do_printk() helper
has been added to the -mm mm-unstable branch. Its filename is
seq_buf-add-seq_buf_do_printk-helper.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/seq_buf-add-seq_buf_do_printk-helper.patch
This patch will later appear in the mm-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days
------------------------------------------------------
From: Sergey Senozhatsky <senozhatsky@chromium.org>
Subject: seq_buf: add seq_buf_do_printk() helper
Date: Sat, 15 Apr 2023 19:01:10 +0900
(akpm: temporary addition for
memcg-use-seq_buf_do_printk-with-mem_cgroup_print_oom_meminfo.patch)
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 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
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/linux/seq_buf.h | 2 ++
lib/seq_buf.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
--- a/include/linux/seq_buf.h~seq_buf-add-seq_buf_do_printk-helper
+++ a/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_do_printk(struct seq_buf *s, const char *lvl);
+
#endif /* _LINUX_SEQ_BUF_H */
--- a/lib/seq_buf.c~seq_buf-add-seq_buf_do_printk-helper
+++ a/lib/seq_buf.c
@@ -93,6 +93,38 @@ int seq_buf_printf(struct seq_buf *s, co
}
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
/**
* seq_buf_bprintf - Write the printf string from binary arguments
_
Patches currently in -mm which might be from senozhatsky@chromium.org are
seq_buf-add-seq_buf_do_printk-helper.patch
reply other threads:[~2023-05-03 2:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230503021738.0C358C433D2@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=pmladek@suse.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.