diff mbox series

[2/2] trace-cmd library: Do not read CPU greater than CPUs registered

Message ID 20220312234032.127108-3-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 3869d1529a99a08645d8ef41077251ead78c8ebb
Headers show
Series trace-cmd library: Fix sparse cpu_data | expand

Commit Message

Steven Rostedt March 12, 2022, 11:40 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

If tracecmd_read_cpu_first() is called with a CPU that is greater than the
number of CPUs in the handle, just return NULL.

This happened when kernelshark would get the number of CPUs returned by
the tep handler, but they are not stored in the trace.dat file.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 lib/trace-cmd/trace-input.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c
index da922834de1f..313534d09e86 100644
--- a/lib/trace-cmd/trace-input.c
+++ b/lib/trace-cmd/trace-input.c
@@ -2025,9 +2025,15 @@  int tracecmd_refresh_record(struct tracecmd_input *handle,
 struct tep_record *
 tracecmd_read_cpu_first(struct tracecmd_input *handle, int cpu)
 {
+	unsigned long long page_offset;
 	int ret;
 
-	ret = get_page(handle, cpu, handle->cpu_data[cpu].file_offset);
+	if (cpu > handle->cpus)
+		return NULL;
+
+	page_offset = calc_page_offset(handle, handle->cpu_data[cpu].file_offset);
+
+	ret = get_page(handle, cpu, page_offset);
 	if (ret < 0)
 		return NULL;