From 05134d15375ce9fc57a91453999729d861efe9f9 Mon Sep 17 00:00:00 2001 From: Swapnil Sapkal Date: Tue, 27 Jan 2026 18:49:56 +0000 Subject: [PATCH] perf util: Fix NULL check in cpumask_to_cpulist() The function cpumask_to_cpulist() allocates memory with calloc() and stores the result in 'bm', but then incorrectly checks 'cpumask' for NULL instead of 'bm'. This means that if the allocation fails, the function will dereference a NULL pointer when trying to access 'bm'. Fix the check to test the correct variable 'bm'. Fixes: d40c68a49f69c9bd ("perf header: Support CPU DOMAIN relation info") Reviewed-by: Shrikanth Hegde Signed-off-by: Swapnil Sapkal Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Anubhav Shelat Cc: Chen Yu Cc: Gautham Shenoy Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Thomas Falcon Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 94f5a2ece245..8b893de35f77 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -279,7 +279,7 @@ void cpumask_to_cpulist(char *cpumask, char *cpulist) return; bm = calloc(bm_size, sizeof(unsigned long)); - if (!cpumask) + if (!bm) goto free_bm; for (i = 0; i < bm_size; i++) { -- 2.47.3