History

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]

Woradorn Laodhanadhaworn committed 4 months ago

Commit efdcfd91 parent dca6a221 file · +13 −3Browse files

Unified · Split

kernel/trace/trace_events.c+13−3
@@ -14,6 +14,7 @@ · 13 unmodified lines
1414 #include <linux/workqueue.h>
1515 #include <linux/security.h>
1616 #include <linux/spinlock.h>
17+#include <linux/seq_buf.h>
1718 #include <linux/kthread.h>
1819 #include <linux/tracefs.h>
1920 #include <linux/uaccess.h>
@@ -4604,13 +4605,20 @@ extern struct trace_event_call *__start_ftrace_events[]; · 4584 unmodified lines
46044605 extern struct trace_event_call *__stop_ftrace_events[];
46054606
46064607 static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
4608+static struct seq_buf bootup_event_seq __initdata = {
4609+ .buffer = bootup_event_buf,
4610+ .size = sizeof(bootup_event_buf),
4611+};
46074612
46084613 static __init int setup_trace_event(char *str)
46094614 {
4610− if (bootup_event_buf[0] != '\0')
4611− strlcat(bootup_event_buf, ",", COMMAND_LINE_SIZE);
4615+ if (seq_buf_used(&bootup_event_seq) > 0)
4616+ seq_buf_puts(&bootup_event_seq, ",");
4617+
4618+ seq_buf_puts(&bootup_event_seq, str);
46124619
4613− strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE);
4620+ if (seq_buf_has_overflowed(&bootup_event_seq))
4621+ return -ENOMEM;
46144622
46154623 trace_set_ring_buffer_expanded(NULL);
46164624 disable_tracing_selftest("running event tracing");
@@ -4869,6 +4877,7 @@ static __init int event_trace_enable(void) · 252 unmodified lines
48694877 */
48704878 __trace_early_add_events(tr);
48714879
4880+ seq_buf_str(&bootup_event_seq);
48724881 early_enable_events(tr, bootup_event_buf, false);
48734882
48744883 trace_printk_start_comm();
@@ -4897,6 +4906,7 @@ static __init int event_trace_enable_again(void) · 22 unmodified lines
48974906 if (!tr)
48984907 return -ENODEV;
48994908
4909+ seq_buf_str(&bootup_event_seq);
49004910 early_enable_events(tr, bootup_event_buf, true);
49014911
49024912 return 0;