Skip to content

Commit cb24693

Browse files
ytcooderostedt
authored andcommitted
tracing: Use strim() to remove whitespace instead of doing it manually
The tracing_set_trace_write() function just removes the trailing whitespace from the user supplied tracer name, but the leading whitespace should also be removed. In addition, if the user supplied tracer name contains only a few whitespace characters, the first one will not be removed using the current method, which results it a single whitespace character left in the buf. To fix all of these issues, we use strim() to correctly remove both the leading and trailing whitespace. Link: https://lkml.kernel.org/r/20220121095623.1826679-1-ytcoode@gmail.com Signed-off-by: Yuntao Wang <ytcoode@gmail.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 2889c65 commit cb24693

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

kernel/trace/trace.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6461,7 +6461,7 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
64616461
{
64626462
struct trace_array *tr = filp->private_data;
64636463
char buf[MAX_TRACER_SIZE+1];
6464-
int i;
6464+
char *name;
64656465
size_t ret;
64666466
int err;
64676467

@@ -6475,11 +6475,9 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
64756475

64766476
buf[cnt] = 0;
64776477

6478-
/* strip ending whitespace. */
6479-
for (i = cnt - 1; i > 0 && isspace(buf[i]); i--)
6480-
buf[i] = 0;
6478+
name = strim(buf);
64816479

6482-
err = tracing_set_tracer(tr, buf);
6480+
err = tracing_set_tracer(tr, name);
64836481
if (err)
64846482
return err;
64856483

0 commit comments

Comments
 (0)