aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/perf/threadmap.c
diff options
context:
space:
mode:
authorIan Rogers <[email protected]>2025-05-19 19:51:38 +0000
committerArnaldo Carvalho de Melo <[email protected]>2025-05-21 18:07:13 +0000
commiteead8a0114775c7250ae27197ac3f3e5bbc567df (patch)
tree46c22de59209d1d173be95b69953496a960f2842 /tools/lib/perf/threadmap.c
parentperf test amd: Skip amd-ibs-period test on kernel < v6.15 (diff)
downloadkernel-eead8a0114775c7250ae27197ac3f3e5bbc567df.tar.gz
kernel-eead8a0114775c7250ae27197ac3f3e5bbc567df.zip
libperf threadmap: Don't segv for index 0 for the NULL 'struct perf_thread_map' pointer
perf_thread_map__nr() returns length 1 if the perf_thread_map is NULL, meaning index 0 is valid. When perf_thread_map__pid() of index 0 is read then return the expected "any" -1 value. Assert this is only done for index 0. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Gautam Menghani <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Howard Chu <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Madhavan Srinivasan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Diffstat (limited to 'tools/lib/perf/threadmap.c')
-rw-r--r--tools/lib/perf/threadmap.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/lib/perf/threadmap.c b/tools/lib/perf/threadmap.c
index 07968f3ea093..3ca9ba4987fc 100644
--- a/tools/lib/perf/threadmap.c
+++ b/tools/lib/perf/threadmap.c
@@ -97,5 +97,10 @@ int perf_thread_map__nr(struct perf_thread_map *threads)
pid_t perf_thread_map__pid(struct perf_thread_map *map, int idx)
{
+ if (!map) {
+ assert(idx == 0);
+ return -1;
+ }
+
return map->map[idx].pid;
}