[PATCH v1 2/6] perf util: Fix NULL check in cpumask_to_cpulist()

From
Swapnil Sapkal <hidden>
Date
2026-01-27 18:51:16
Also in
lkml
Reply to
Swapnil Sapkal, 2026-01-27
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: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
Signed-off-by: Swapnil Sapkal <redacted>
---
 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 03a603fbcd7d..c83e59e8c787 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -278,7 +278,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.43.0
Thread (13 messages) 13 messages, 3 authors, last reply 2026-01-28
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help