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.

Signed-off-by: Thomas Weißschuh <[email protected]>
---
 include/linux/trace_events.h |  2 +-
 kernel/trace/trace_events.c  | 17 ++++++-----------
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 308c76b57d13..460d820fe7a4 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -873,7 +873,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 6aa32c492280..c75a7f5b55de 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -1411,14 +1411,17 @@ 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 *_buf, int set)
 {
        char *event = NULL, *sub = NULL, *match, *mod;
-       int ret;
 
        if (!tr)
                return -ENOENT;
 
+       char *buf __free(kfree) = kstrdup(_buf, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
        /* Modules events can be appended with :mod:<module> */
        mod = strstr(buf, ":mod:");
        if (mod) {
@@ -1455,15 +1458,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.55.0


Reply via email to