tracing: Clean up tracing_fill_pipe_page()
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>
Mon, 17 Nov 2014 18:12:22 +0000 (13:12 -0500)
committerSteven Rostedt <rostedt@goodmis.org>
Thu, 20 Nov 2014 03:01:14 +0000 (22:01 -0500)
The function tracing_fill_pipe_page() logic is a little confusing with the
use of count saving the seq.len and reusing it.

Instead of subtracting a number that is calculated from the saved
value of the seq.len from seq.len, just save the seq.len at the start
and if we need to reset it, just assign it again.

When the seq_buf overflow is len == size + 1, the current logic will
break. Changing it to use a saved length for resetting back to the
original value is more robust and will work when we change the way
seq_buf sets the overflow.

Link: http://lkml.kernel.org/r/20141118161546.GJ23958@pathway.suse.cz
Reviewed-by: Petr Mladek <pmladek@suse.cz>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
kernel/trace/trace.c

index 7d7a07e9b9e95427e1d9ca76a77b77e851a53ed9..0aa75be843a0b7329ce3bac1d27ffbb9f3ac2fb0 100644 (file)
@@ -4575,20 +4575,33 @@ static size_t
 tracing_fill_pipe_page(size_t rem, struct trace_iterator *iter)
 {
        size_t count;
+       int save_len;
        int ret;
 
        /* Seq buffer is page-sized, exactly what we need. */
        for (;;) {
-               count = iter->seq.seq.len;
+               save_len = iter->seq.seq.len;
                ret = print_trace_line(iter);
-               count = iter->seq.seq.len - count;
-               if (rem < count) {
-                       rem = 0;
-                       iter->seq.seq.len -= count;
+
+               if (trace_seq_has_overflowed(&iter->seq)) {
+                       iter->seq.seq.len = save_len;
                        break;
                }
+
+               /*
+                * This should not be hit, because it should only
+                * be set if the iter->seq overflowed. But check it
+                * anyway to be safe.
+                */
                if (ret == TRACE_TYPE_PARTIAL_LINE) {
-                       iter->seq.seq.len -= count;
+                       iter->seq.seq.len = save_len;
+                       break;
+               }
+
+               count = iter->seq.seq.len - save_len;
+               if (rem < count) {
+                       rem = 0;
+                       iter->seq.seq.len = save_len;
                        break;
                }