From efdcfd9b4f4f07aa70663ee02a79dbdf980bf582 Mon Sep 17 00:00:00 2001 From: Woradorn Laodhanadhaworn Date: Mon, 13 Jul 2026 11:52:49 +0700 Subject: [PATCH] tracing: Use seq_buf for string concatenation 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@gmail.com Signed-off-by: Woradorn Laodhanadhaworn [ Moved placement of #include ] Signed-off-by: Steven Rostedt --- 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 #include #include +#include #include #include #include @@ -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, ","); - strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE); + seq_buf_puts(&bootup_event_seq, str); + + 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;