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]
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <linux/workqueue.h> |
| 15 | 15 | #include <linux/security.h> |
| 16 | 16 | #include <linux/spinlock.h> |
| 17 | +#include <linux/seq_buf.h> | |
| 17 | 18 | #include <linux/kthread.h> |
| 18 | 19 | #include <linux/tracefs.h> |
| 19 | 20 | #include <linux/uaccess.h> |
| @@ -4604,13 +4605,20 @@ extern struct trace_event_call *__start_ftrace_events[]; · 4584 unmodified lines | ||
| 4604 | 4605 | extern struct trace_event_call *__stop_ftrace_events[]; |
| 4605 | 4606 | |
| 4606 | 4607 | 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 | +}; | |
| 4607 | 4612 | |
| 4608 | 4613 | static __init int setup_trace_event(char *str) |
| 4609 | 4614 | { |
| 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); | |
| 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 | 4623 | trace_set_ring_buffer_expanded(NULL); |
| 4616 | 4624 | disable_tracing_selftest("running event tracing"); |
| @@ -4869,6 +4877,7 @@ static __init int event_trace_enable(void) · 252 unmodified lines | ||
| 4869 | 4877 | */ |
| 4870 | 4878 | __trace_early_add_events(tr); |
| 4871 | 4879 | |
| 4880 | + seq_buf_str(&bootup_event_seq); | |
| 4872 | 4881 | early_enable_events(tr, bootup_event_buf, false); |
| 4873 | 4882 | |
| 4874 | 4883 | trace_printk_start_comm(); |
| @@ -4897,6 +4906,7 @@ static __init int event_trace_enable_again(void) · 22 unmodified lines | ||
| 4897 | 4906 | if (!tr) |
| 4898 | 4907 | return -ENODEV; |
| 4899 | 4908 | |
| 4909 | + seq_buf_str(&bootup_event_seq); | |
| 4900 | 4910 | early_enable_events(tr, bootup_event_buf, true); |
| 4901 | 4911 | |
| 4902 | 4912 | return 0; |