Skip to content

Commit 4c04b4b

Browse files
committed
Merge tag 'trace-v4.8-rc7' of git://git.kernel.org/pub/scm/linux/kernel/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
2 parents 90b75db + 1ae2293 commit 4c04b4b

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

kernel/trace/trace.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,19 +5124,20 @@ tracing_read_pipe(struct file *filp, char __user *ubuf,
51245124
struct trace_iterator *iter = filp->private_data;
51255125
ssize_t sret;
51265126

5127-
/* return any leftover data */
5128-
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
5129-
if (sret != -EBUSY)
5130-
return sret;
5131-
5132-
trace_seq_init(&iter->seq);
5133-
51345127
/*
51355128
* Avoid more than one consumer on a single file descriptor
51365129
* This is just a matter of traces coherency, the ring buffer itself
51375130
* is protected.
51385131
*/
51395132
mutex_lock(&iter->mutex);
5133+
5134+
/* return any leftover data */
5135+
sret = trace_seq_to_user(&iter->seq, ubuf, cnt);
5136+
if (sret != -EBUSY)
5137+
goto out;
5138+
5139+
trace_seq_init(&iter->seq);
5140+
51405141
if (iter->trace->read) {
51415142
sret = iter->trace->read(iter, filp, ubuf, cnt, ppos);
51425143
if (sret)
@@ -6163,9 +6164,6 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
61636164
return -EBUSY;
61646165
#endif
61656166

6166-
if (splice_grow_spd(pipe, &spd))
6167-
return -ENOMEM;
6168-
61696167
if (*ppos & (PAGE_SIZE - 1))
61706168
return -EINVAL;
61716169

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

6176+
if (splice_grow_spd(pipe, &spd))
6177+
return -ENOMEM;
6178+
61786179
again:
61796180
trace_access_lock(iter->cpu_file);
61806181
entries = ring_buffer_entries_cpu(iter->trace_buffer->buffer, iter->cpu_file);
@@ -6232,19 +6233,21 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
62326233
/* did we read anything? */
62336234
if (!spd.nr_pages) {
62346235
if (ret)
6235-
return ret;
6236+
goto out;
62366237

6238+
ret = -EAGAIN;
62376239
if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK))
6238-
return -EAGAIN;
6240+
goto out;
62396241

62406242
ret = wait_on_pipe(iter, true);
62416243
if (ret)
6242-
return ret;
6244+
goto out;
62436245

62446246
goto again;
62456247
}
62466248

62476249
ret = splice_to_pipe(pipe, &spd);
6250+
out:
62486251
splice_shrink_spd(&spd);
62496252

62506253
return ret;

0 commit comments

Comments
 (0)