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 <swapnil.sapkal@amd.com>
---
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