From 2d3135cdedfe26e0867a3f45a273dcdbf3bdbe86 Mon Sep 17 00:00:00 2001 From: longlong yan Date: Wed, 2 Sep 2026 15:09:13 +0800 Subject: [PATCH] perf bench numa: Add NULL check after calloc() Two calloc() calls in the numa benchmark lack NULL return checks, leading to potential NULL pointer dereferences on allocation failure: 1. worker_process(): the allocated `pthreads` array is used in the following for-loop via pthreads[t] without checking for NULL. 2. __bench_numa(): the allocated `pids` array is used in the following for-loop via pids[i] without checking for NULL. Add BUG_ON() checks after each calloc(), consistent with the existing NULL check style used elsewhere in the same file (e.g., node_present and nodes allocations). Signed-off-by: longlong yan Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bench/numa.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c index 42d7afc03f9b..371a74e3da1b 100644 --- a/tools/perf/bench/numa.c +++ b/tools/perf/bench/numa.c @@ -1419,6 +1419,7 @@ static void worker_process(int process_nr) bind_to_cpumask(td->bind_cpumask); pthreads = calloc(g->p.nr_threads, sizeof(pthread_t)); + BUG_ON(!pthreads); process_data = setup_private_data(g->p.bytes_process); if (g->p.show_details >= 3) { @@ -1625,6 +1626,7 @@ static int __bench_numa(const char *name) return -1; pids = calloc(g->p.nr_proc, sizeof(*pids)); + BUG_ON(!pids); pid = -1; if (g->p.serialize_startup) {