[for-next][PATCH 16/16] tracing: Use seq_buf for string concatenation
From: Steven Rostedt
Date: Tue Jul 28 2026 - 20:08:35 EST
From: Woradorn Laodhanadhaworn <woradorn.laon@xxxxxxxxx>
In preparation for removing the strlcat API[1],
replace the string concatenation logic with a struct seq_buf,
which tracks the current position and the remaining space internally.
Use seq_buf_str() to NUL-terminate before passing to early_enable_events().
Link: https://github.com/KSPP/linux/issues/370 [1]
Link: https://patch.msgid.link/20260713045249.69942-1-woradorn.laon@xxxxxxxxx
Signed-off-by: Woradorn Laodhanadhaworn <woradorn.laon@xxxxxxxxx>
[ Moved placement of #include <linux/seq_buf.h> ]
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
kernel/trace/trace_events.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 714285e23a2e..a8590d2394e3 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -14,6 +14,7 @@
#include <linux/workqueue.h>
#include <linux/security.h>
#include <linux/spinlock.h>
+#include <linux/seq_buf.h>
#include <linux/kthread.h>
#include <linux/tracefs.h>
#include <linux/uaccess.h>
@@ -4604,13 +4605,20 @@ extern struct trace_event_call *__start_ftrace_events[];
extern struct trace_event_call *__stop_ftrace_events[];
static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
+static struct seq_buf bootup_event_seq __initdata = {
+ .buffer = bootup_event_buf,
+ .size = sizeof(bootup_event_buf),
+};
static __init int setup_trace_event(char *str)
{
- if (bootup_event_buf[0] != '\0')
- strlcat(bootup_event_buf, ",", COMMAND_LINE_SIZE);
+ if (seq_buf_used(&bootup_event_seq) > 0)
+ seq_buf_puts(&bootup_event_seq, ",");
+
+ seq_buf_puts(&bootup_event_seq, str);
- strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE);
+ if (seq_buf_has_overflowed(&bootup_event_seq))
+ return -ENOMEM;
trace_set_ring_buffer_expanded(NULL);
disable_tracing_selftest("running event tracing");
@@ -4869,6 +4877,7 @@ static __init int event_trace_enable(void)
*/
__trace_early_add_events(tr);
+ seq_buf_str(&bootup_event_seq);
early_enable_events(tr, bootup_event_buf, false);
trace_printk_start_comm();
@@ -4897,6 +4906,7 @@ static __init int event_trace_enable_again(void)
if (!tr)
return -ENODEV;
+ seq_buf_str(&bootup_event_seq);
early_enable_events(tr, bootup_event_buf, true);
return 0;
--
2.53.0