Skip to content

Commit

Permalink
ftrace: fix current_tracer error return
Browse files Browse the repository at this point in the history
The commit (in linux-tip) c2931e0
 ( ftrace: return an error when setting a nonexistent tracer )
added useful code that would error when a bad tracer was written into
the current_tracer file.

But this had a bug if the amount written was more than the amount read by
that code. The first iteration would set the tracer correctly, but since
it did not consume the rest of what was written (usually whitespace), the
userspace utility would continue to write what was not consumed. This
second iteration would fail to find a tracer and return -EINVAL. Funny
thing is that the tracer would have already been set.

This patch just consumes all the data that is written to the file.

Signed-off-by: Steven Rostedt <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
rostedt authored and Ingo Molnar committed Oct 28, 2008
1 parent 21798a8 commit 60063a6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -2377,9 +2377,10 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
int i;
size_t ret;

ret = cnt;

if (cnt > max_tracer_type_len)
cnt = max_tracer_type_len;
ret = cnt;

if (copy_from_user(&buf, ubuf, cnt))
return -EFAULT;
Expand Down Expand Up @@ -2412,8 +2413,8 @@ tracing_set_trace_write(struct file *filp, const char __user *ubuf,
out:
mutex_unlock(&trace_types_lock);

if (ret == cnt)
filp->f_pos += cnt;
if (ret > 0)
filp->f_pos += ret;

return ret;
}
Expand Down

0 comments on commit 60063a6

Please sign in to comment.