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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
 lib/trace-cmd/trace-input.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

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;
 
-- 
2.35.1




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux