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
14#include <linux/workqueue.h>14#include <linux/workqueue.h>
15#include <linux/security.h>15#include <linux/security.h>
16#include <linux/spinlock.h>16#include <linux/spinlock.h>
17#include <linux/seq_buf.h>
17#include <linux/kthread.h>18#include <linux/kthread.h>
18#include <linux/tracefs.h>19#include <linux/tracefs.h>
19#include <linux/uaccess.h>20#include <linux/uaccess.h>
@@ -4604,13 +4605,20 @@ extern struct trace_event_call *__start_ftrace_events[]; · 4584 unmodified lines
4604extern struct trace_event_call *__stop_ftrace_events[];4605extern struct trace_event_call *__stop_ftrace_events[];
4605 4606
4606static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;4607static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
4608static struct seq_buf bootup_event_seq __initdata = {
4609 .buffer = bootup_event_buf,
4610 .size = sizeof(bootup_event_buf),
4611};
4607 4612
4608static __init int setup_trace_event(char *str)4613static __init int setup_trace_event(char *str)
4609{4614{
4610 if (bootup_event_buf[0] != '\0')4615 if (seq_buf_used(&bootup_event_seq) > 0)
4611 strlcat(bootup_event_buf, ",", COMMAND_LINE_SIZE);4616 seq_buf_puts(&bootup_event_seq, ",");
4617
4618 seq_buf_puts(&bootup_event_seq, str);
4612 4619
4613 strlcat(bootup_event_buf, str, COMMAND_LINE_SIZE);4620 if (seq_buf_has_overflowed(&bootup_event_seq))
4621 return -ENOMEM;
4614 4622
4615 trace_set_ring_buffer_expanded(NULL);4623 trace_set_ring_buffer_expanded(NULL);
4616 disable_tracing_selftest("running event tracing");4624 disable_tracing_selftest("running event tracing");
@@ -4869,6 +4877,7 @@ static __init int event_trace_enable(void) · 252 unmodified lines
4869 */4877 */
4870 __trace_early_add_events(tr);4878 __trace_early_add_events(tr);
4871 4879
4880 seq_buf_str(&bootup_event_seq);
4872 early_enable_events(tr, bootup_event_buf, false);4881 early_enable_events(tr, bootup_event_buf, false);
4873 4882
4874 trace_printk_start_comm();4883 trace_printk_start_comm();
@@ -4897,6 +4906,7 @@ static __init int event_trace_enable_again(void) · 22 unmodified lines
4897 if (!tr)4906 if (!tr)
4898 return -ENODEV;4907 return -ENODEV;
4899 4908
4909 seq_buf_str(&bootup_event_seq);
4900 early_enable_events(tr, bootup_event_buf, true);4910 early_enable_events(tr, bootup_event_buf, true);
4901 4911
4902 return 0;4912 return 0;