diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-11 17:15:36 -0500 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2024-01-11 17:51:53 -0500 |
commit | a49c838e91b10c41058bcd4d7dbcf9980a3c625d (patch) | |
tree | 411d38eea665d3cc7db2206b80d994933a4c3c5e | |
parent | 56d07aeb09d6c063686971c051210ca679d39b0c (diff) | |
download | trace-cmd-a49c838e91b10c41058bcd4d7dbcf9980a3c625d.tar.gz |
libtracecmd: Use cpu_data[cpu]->cpus and not ->max_cpu
The handle->cpu_data[cpu]->max_cpu is the largest number CPU that is
recorded in the trace, where as cpu_data[cpu]->cpus is the number of
handle->cpu_data[] entries.
The iterator loops mistakenly used the max_cpu field instead of the cpus
field and this can cause errors if the two are not the same. This is the
case if one of the CPUs contained no data, it will not have a cpu_data[]
entry and will be skipped.
Link: https://lore.kernel.org/linux-trace-devel/20240111222201.154686-2-rostedt@goodmis.org
Fixes: 2cb6cc2f4 ("tracecmd library: Add tracecmd_iterate_events()")
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | lib/trace-cmd/trace-input.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 055b4e77..b89167de 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2822,11 +2822,11 @@ int tracecmd_iterate_events(struct tracecmd_input *handle, return -1; } - records = calloc(handle->max_cpu, sizeof(*records)); + records = calloc(handle->cpus, sizeof(*records)); if (!records) return -1; - for (cpu = 0; cpu < handle->max_cpu; cpu++) { + for (cpu = 0; cpu < handle->cpus; cpu++) { if (cpus && !CPU_ISSET_S(cpu, cpu_size, cpus)) continue; @@ -2835,7 +2835,7 @@ int tracecmd_iterate_events(struct tracecmd_input *handle, do { next_cpu = -1; - for (cpu = 0; cpu < handle->max_cpu; cpu++) { + for (cpu = 0; cpu < handle->cpus; cpu++) { record = records[cpu]; if (!record) continue; @@ -2858,7 +2858,7 @@ int tracecmd_iterate_events(struct tracecmd_input *handle, } while (next_cpu >= 0 && ret == 0); /* Need to unlock and free the records */ - for (cpu = 0; cpu < handle->max_cpu; cpu++) { + for (cpu = 0; cpu < handle->cpus; cpu++) { int offset; if (!records[cpu]) @@ -3028,7 +3028,7 @@ int tracecmd_iterate_events_reverse(struct tracecmd_input *handle, struct tep_record **records; struct tep_record *record; int next_cpu; - int max_cpus = handle->max_cpu; + int max_cpus = handle->cpus; int cpu; int ret = 0; @@ -3122,7 +3122,7 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles, for (i = 0; i < nr_handles; i++) { handle = handles[i]; - cpus += handle->max_cpu; + cpus += handle->cpus; } records = calloc(cpus, sizeof(*records)); @@ -3132,7 +3132,7 @@ int tracecmd_iterate_events_multi(struct tracecmd_input **handles, for (i = 0; i < nr_handles; i++) { handle = handles[i]; handle->start_cpu = all_cpus; - for (cpu = 0; cpu < handle->max_cpu; cpu++) { + for (cpu = 0; cpu < handle->cpus; cpu++) { records[all_cpus + cpu].record = tracecmd_peek_data(handle, cpu); records[all_cpus + cpu].handle = handle; } |