[for-next][PATCH 04/18] tracing: Stop modifying the input buffer in ftrace_set_clr_event()
From: Steven Rostedt
Date: Fri Oct 16 2026 - 10:38:47 EST
From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= <thomas.weissschuh@xxxxxxxxxxxxx>
ftrace_set_clr_event() modifies its input buffer during parsing.
Before returning to the caller these modifications are undone.
This is restoration is error prone and was forgotten before.
Upcoming changes will also make it more complicated.
Copy the input argument and modify that copy and drop the
restoration logic.
Also mark the input argument as const.
Link: https://patch.msgid.link/20260908-tracing-cli-event-filter-v2-3-05396a3fb663@xxxxxxxxxxxxx
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
Signed-off-by: Steven Rostedt <rostedt@xxxxxxxxxxx>
---
include/linux/trace_events.h | 2 +-
kernel/trace/trace_events.c | 19 ++++++++-----------
2 files changed, 9 insertions(+), 12 deletions(-)
diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index d0259a515a83..8a396ae51fef 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -883,7 +883,7 @@ extern int trace_add_event_call(struct trace_event_call *call);
extern int trace_remove_event_call(struct trace_event_call *call);
extern int trace_event_get_offsets(struct trace_event_call *call);
-int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set);
+int ftrace_set_clr_event(struct trace_array *tr, const char *buf, int set);
int trace_set_clr_event(const char *system, const char *event, int set);
int trace_array_set_clr_event(struct trace_array *tr, const char *system,
const char *event, bool enable);
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 1bd227282729..de964dd2878b 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1443,14 +1443,19 @@ static int __ftrace_set_clr_event(struct trace_array *tr, const char *match,
return ret;
}
-int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
+int ftrace_set_clr_event(struct trace_array *tr, const char *arg_buf, int set)
{
char *event = NULL, *sub = NULL, *match, *mod;
- int ret;
+ char *buf;
if (!tr)
return -ENOENT;
+ char *dupped_buf __free(kfree) = kstrdup(arg_buf, GFP_KERNEL);
+ if (!dupped_buf)
+ return -ENOMEM;
+ buf = dupped_buf;
+
/* Modules events can be appended with :mod:<module> */
mod = strstr(buf, ":mod:");
if (mod) {
@@ -1487,15 +1492,7 @@ int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set)
match = NULL;
}
- ret = __ftrace_set_clr_event(tr, match, sub, event, set, mod);
-
- /* Put back the colon to allow this to be called again */
- if (buf)
- *(buf - 1) = ':';
- if (mod)
- *(mod - 5) = ':';
-
- return ret;
+ return __ftrace_set_clr_event(tr, match, sub, event, set, mod);
}
/**
--
2.53.0