Commit a0a41736 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map



Passing an empty map to perf_cpu_map__max triggered a SEGV. Explicitly
test for the empty map.

Reported-by: default avatarIngo Molnar <mingo@kernel.org>
Closes: https://lore.kernel.org/linux-perf-users/aSwt7yzFjVJCEmVp@gmail.com/


Tested-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Tested-by: default avatarThomas Richter <tmricht@linux.ibm.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent 6744c0b1
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -368,10 +368,12 @@ struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map)
		.cpu = -1
	};

	// cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as well.
	return __perf_cpu_map__nr(map) > 0
		? __perf_cpu_map__cpu(map, __perf_cpu_map__nr(map) - 1)
		: result;
	if (!map)
		return result;

	// The CPUs are always sorted and nr is always > 0 as 0 length map is
	// encoded as NULL.
	return __perf_cpu_map__cpu(map, __perf_cpu_map__nr(map) - 1);
}

/** Is 'b' a subset of 'a'. */