diff options
| author | Ian Rogers <irogers@google.com> | 2026-08-09 00:14:54 -0700 |
|---|---|---|
| committer | Namhyung Kim <namhyung@kernel.org> | 2026-08-09 22:02:42 -0700 |
| commit | 16a12a54e9a1151a37aab74914a51b86f7f58d0e (patch) | |
| tree | 4ca6d096fd0da5843eaafa244a07bc36a494ec94 /tools/perf | |
| parent | 1ec13016ba36f1bf7dc61e054068fe00f2f628c7 (diff) | |
| download | linux-next-16a12a54e9a1151a37aab74914a51b86f7f58d0e.tar.gz linux-next-16a12a54e9a1151a37aab74914a51b86f7f58d0e.zip | |
perf synthetic-events: Fix divide by zero in perf_event__synthesize_threads
If scandir() finds no matching tasks in /proc, n is 0. If thread_nr is > 1,
we bypass the single-thread fast path and then clamp thread_nr to n, making
it 0. This results in a divide by zero when calculating num_per_thread.
Handle n <= 1 early to use the single-thread fast path and prevent the
crash.
Fixes: 340b47f510bb ("perf top: Implement multithreading for perf_event__synthesize_threads")
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Diffstat (limited to 'tools/perf')
| -rw-r--r-- | tools/perf/util/synthetic-events.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index 3583a60cc487..0c150193cca8 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1175,7 +1175,7 @@ int perf_event__synthesize_threads(const struct perf_tool *tool, else thread_nr = nr_threads_synthesize; - if (thread_nr <= 1) { + if (thread_nr <= 1 || n <= 1) { err = __perf_event__synthesize_threads(tool, process, machine, needs_mmap, mmap_data, |
