Skip to content

Commit

Permalink
Merge tag 'trace-v4.8-rc7' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/git/rostedt/linux-trace

Pull tracefs fixes from Steven Rostedt:
 "Al Viro has been looking at the tracefs code, and has pointed out some
  issues.  This contains one fix by me and one by Al.  I'm sure that
  he'll come up with more but for now I tested these patches and they
  don't appear to have any negative impact on tracing"

* tag 'trace-v4.8-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
  fix memory leaks in tracing_buffers_splice_read()
  tracing: Move mutex to protect against resetting of seq data
  • Loading branch information
torvalds committed Sep 26, 2016
2 parents 90b75db + 1ae2293 commit 4c04b4b
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions kernel/trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5124,19 +5124,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
struct trace_iterator *iter = filp->private_data;
ssize_t sret;

/* return any leftover data */
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
if (sret != -EBUSY)
return sret;

trace_seq_init(&iter->seq);

/*
* Avoid more than one consumer on a single file descriptor
* This is just a matter of traces coherency, the ring buffer itself
* is protected.
*/
mutex_lock(&iter->mutex);

/* return any leftover data */
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
if (sret != -EBUSY)
goto out;

trace_seq_init(&iter->seq);

if (iter->trace->read) {
sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
if (sret)
Expand Down Expand Up @@ -6163,9 +6164,6 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
return -EBUSY;
#endif

if (splice_grow_spd(pipe, &spd))
return -ENOMEM;

if (*ppos & (PAGE_SIZE - 1))
return -EINVAL;

Expand All @@ -6175,6 +6173,9 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
len &= PAGE_MASK;
}

if (splice_grow_spd(pipe, &spd))
return -ENOMEM;

again:
trace_access_lock(iter->cpu_file);
entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file);
Expand Down Expand Up @@ -6232,19 +6233,21 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
/* did we read anything? */
if (!spd.nr_pages) {
if (ret)
return ret;
goto out;

ret = -EAGAIN;
if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
return -EAGAIN;
goto out;

ret = wait_on_pipe(iter, true);
if (ret)
return ret;
goto out;

goto again;
}

ret = splice_to_pipe(pipe, &spd);
out:
splice_shrink_spd(&spd);

return ret;
Expand Down

0 comments on commit 4c04b4b

Please sign in to comment.