[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <aeed348204d6729e95eedb0766349ec30c0f162c.1711380724.git.jani.nikula@intel.com>
Date: Mon, 25 Mar 2024 17:36:33 +0200
From: Jani Nikula <jani.nikula@...el.com>
To: Andrew Morton <akpm@...ux-foundation.org>,
Greg KH <gregkh@...uxfoundation.org>,
linux-kernel@...r.kernel.org
Cc: jani.nikula@...el.com
Subject: [RFC 2/4] kernel/panic: convert print_tainted() to use struct seq_buf internally
Convert print_tainted() to use struct seq_buf internally in order to be
more aware of the buffer constraints as well as make it easier to extend
in follow-up work.
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Greg KH <gregkh@...uxfoundation.org>
Signed-off-by: Jani Nikula <jani.nikula@...el.com>
---
kernel/panic.c | 38 ++++++++++++++++++++++++--------------
1 file changed, 24 insertions(+), 14 deletions(-)
diff --git a/kernel/panic.c b/kernel/panic.c
index b6d4d1da1eaa..d2d5f0a4b514 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -35,6 +35,7 @@
#include <linux/debugfs.h>
#include <linux/sysfs.h>
#include <linux/context_tracking.h>
+#include <linux/seq_buf.h>
#include <trace/events/error_report.h>
#include <asm/sections.h>
@@ -498,6 +499,25 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
[ TAINT_TEST ] = { 'N', ' ', true },
};
+static void print_tainted_seq(struct seq_buf *s)
+{
+ int i;
+
+ if (!tainted_mask) {
+ seq_buf_puts(s, "Not tainted");
+ return;
+ }
+
+ seq_buf_printf(s, "Tainted: ");
+ for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
+ const struct taint_flag *t = &taint_flags[i];
+ bool is_set = test_bit(i, &tainted_mask);
+ char c = is_set ? t->c_true : t->c_false;
+
+ seq_buf_putc(s, c);
+ }
+}
+
/**
* print_tainted - return a string to represent the kernel taint state.
*
@@ -509,25 +529,15 @@ const struct taint_flag taint_flags[TAINT_FLAGS_COUNT] = {
const char *print_tainted(void)
{
static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")];
- char *s;
- int i;
+ struct seq_buf s;
BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT);
- if (!tainted_mask) {
- snprintf(buf, sizeof(buf), "Not tainted");
- return buf;
- }
+ seq_buf_init(&s, buf, sizeof(buf));
- s = buf + sprintf(buf, "Tainted: ");
- for (i = 0; i < TAINT_FLAGS_COUNT; i++) {
- const struct taint_flag *t = &taint_flags[i];
- *s++ = test_bit(i, &tainted_mask) ?
- t->c_true : t->c_false;
- }
- *s = 0;
+ print_tainted_seq(&s);
- return buf;
+ return seq_buf_str(&s);
}
int test_taint(unsigned flag)
--
2.39.2
Powered by blists - more mailing lists