diff mbox series

[05/10] trace-cmd library: Fix read_data() with error from tracefs_cpu_read()

Message ID 20230106183930.12565-6-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 2391750cceb385ba7d8e68d6337469eccfa5cecc
Headers show
Series trace-cmd: Fix trace-cmd stream | expand

Commit Message

Steven Rostedt Jan. 6, 2023, 6:39 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If tracefs_cpu_read() has an error, it will return a negative value. But the
value is then used as an index. An error check is required to make sure that
if an error is returned from tracefs_cpu_read() the function exits with that
error and does not continue further.

Fixes: 2610bdcde ("trace-cmd library: Use tracefs_cpu for recorder helpers")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-recorder.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c
index 79b95ce1193d..db159e5e5d14 100644
--- a/lib/trace-cmd/trace-recorder.c
+++ b/lib/trace-cmd/trace-recorder.c
@@ -323,6 +323,8 @@  static long read_data(struct tracecmd_recorder *recorder)
 	long r, w;
 
 	r = tracefs_cpu_read(recorder->tcpu, buf, nonblock);
+	if (r < 0)
+		return r;
 
 	left = r;
 	do {