* [PATCH v2] tracing: Use seq_buf for string concatenation
@ 2026-06-22 9:46 Woradorn Laodhanadhaworn
2026-06-29 18:39 ` Steven Rostedt
0 siblings, 1 reply; 2+ messages in thread
From: Woradorn Laodhanadhaworn @ 2026-06-22 9:46 UTC (permalink / raw)
To: rostedt
Cc: mhiramat, mathieu.desnoyers, linux-kernel, linux-trace-kernel,
linux-hardening, linux-kernel-mentees, shuah, skhan, me,
jkoolstra, woradorn.laon
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]
Signed-off-by: Woradorn Laodhanadhaworn <woradorn.laon@gmail.com>
---
v1 -> v2: Fixed WARN_ON when booting with empty trace_event.
v1: https://lore.kernel.org/all/20260620175441.223342-1-woradorn.laon@gmail.com
kernel/trace/trace_events.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index c46e623e7e0d..1be62a46e49a 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -22,6 +22,7 @@
#include <linux/sort.h>
#include <linux/slab.h>
#include <linux/delay.h>
+#include <linux/seq_buf.h>
#include <trace/events/sched.h>
#include <trace/syscall.h>
@@ -4500,14 +4501,20 @@ static void __add_event_to_tracers(struct trace_event_call *call)
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_buf __initdata = {
+ .buffer = (char[COMMAND_LINE_SIZE]) {},
+ .size = COMMAND_LINE_SIZE,
+};
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_buf) > 0)
+ seq_buf_puts(&bootup_event_buf, ",");
+
+ seq_buf_puts(&bootup_event_buf, str);
- strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE);
+ if (seq_buf_has_overflowed(&bootup_event_buf))
+ return -ENOMEM;
trace_set_ring_buffer_expanded(NULL);
disable_tracing_selftest("running event tracing");
@@ -4766,7 +4773,7 @@ static __init int event_trace_enable(void)
*/
__trace_early_add_events(tr);
- early_enable_events(tr, bootup_event_buf, false);
+ early_enable_events(tr, (char *)seq_buf_str(&bootup_event_buf), false);
trace_printk_start_comm();
@@ -4794,7 +4801,7 @@ static __init int event_trace_enable_again(void)
if (!tr)
return -ENODEV;
- early_enable_events(tr, bootup_event_buf, true);
+ early_enable_events(tr, (char *)seq_buf_str(&bootup_event_buf), true);
return 0;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] tracing: Use seq_buf for string concatenation
2026-06-22 9:46 [PATCH v2] tracing: Use seq_buf for string concatenation Woradorn Laodhanadhaworn
@ 2026-06-29 18:39 ` Steven Rostedt
0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2026-06-29 18:39 UTC (permalink / raw)
To: Woradorn Laodhanadhaworn
Cc: mhiramat, mathieu.desnoyers, linux-kernel, linux-trace-kernel,
linux-hardening, linux-kernel-mentees, shuah, skhan, me,
jkoolstra
On Mon, 22 Jun 2026 16:46:23 +0700
Woradorn Laodhanadhaworn <woradorn.laon@gmail.com> wrote:
>
> #include <trace/events/sched.h>
> #include <trace/syscall.h>
> @@ -4500,14 +4501,20 @@ static void __add_event_to_tracers(struct trace_event_call *call)
> 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;
Keep the above string and just assign it.
> +static struct seq_buf bootup_event_buf __initdata = {
> + .buffer = (char[COMMAND_LINE_SIZE]) {},
> + .size = COMMAND_LINE_SIZE,
> +};
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_buf) > 0)
> + seq_buf_puts(&bootup_event_buf, ",");
> +
> + seq_buf_puts(&bootup_event_buf, str);
>
> - strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE);
> + if (seq_buf_has_overflowed(&bootup_event_buf))
> + return -ENOMEM;
>
> trace_set_ring_buffer_expanded(NULL);
> disable_tracing_selftest("running event tracing");
> @@ -4766,7 +4773,7 @@ static __init int event_trace_enable(void)
> */
> __trace_early_add_events(tr);
>
> - early_enable_events(tr, bootup_event_buf, false);
> + early_enable_events(tr, (char *)seq_buf_str(&bootup_event_buf), false);
The above then would be:
seq_buf_str(&bootup_event_seq);
early_enable_events(tr, bootup_event_buf, false);
Don't typecast a const char* to non const.
>
> trace_printk_start_comm();
>
> @@ -4794,7 +4801,7 @@ static __init int event_trace_enable_again(void)
> if (!tr)
> return -ENODEV;
>
> - early_enable_events(tr, bootup_event_buf, true);
> + early_enable_events(tr, (char *)seq_buf_str(&bootup_event_buf), true);
Same here.
-- Steve
>
> return 0;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-29 18:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 9:46 [PATCH v2] tracing: Use seq_buf for string concatenation Woradorn Laodhanadhaworn
2026-06-29 18:39 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox