Commit 57d2371d authored by Zhang Rui's avatar Zhang Rui Committed by Len Brown
Browse files

tools/power turbostat: Fix illegal memory access when SMT is present and disabled



When SMT is present and disabled, turbostat may under-size
the thread_data array.  This can corrupt results or
cause turbostat to exit with a segmentation fault.

[lenb: commit message]
Fixes: a2b4d0f8 ("tools/power turbostat: Favor cpu# over core#")
Signed-off-by: default avatarZhang Rui <rui.zhang@intel.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 1f318b96
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -9702,13 +9702,12 @@ void allocate_counters(struct counters *counters)
{
	int i;
	int num_cores = topo.cores_per_node * topo.nodes_per_pkg * topo.num_packages;
	int num_threads = topo.threads_per_core * num_cores;

	counters->threads = calloc(num_threads, sizeof(struct thread_data));
	counters->threads = calloc(topo.max_cpu_num + 1, sizeof(struct thread_data));
	if (counters->threads == NULL)
		goto error;

	for (i = 0; i < num_threads; i++)
	for (i = 0; i < topo.max_cpu_num + 1; i++)
		(counters->threads)[i].cpu_id = -1;

	counters->cores = calloc(num_cores, sizeof(struct core_data));