]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf util: Fix NULL check in cpumask_to_cpulist()
authorSwapnil Sapkal <swapnil.sapkal@amd.com>
Tue, 27 Jan 2026 18:49:56 +0000 (18:49 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 28 Jan 2026 18:18:24 +0000 (15:18 -0300)
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 <sshegde@linux.ibm.com>
Signed-off-by: Swapnil Sapkal <swapnil.sapkal@amd.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Anubhav Shelat <ashelat@redhat.com>
Cc: Chen Yu <yu.c.chen@intel.com>
Cc: Gautham Shenoy <gautham.shenoy@amd.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/util.c

index 94f5a2ece245863b9999ef017812133f0e1bf953..8b893de35f777db05b5c0c14f179da1d1efb5109 100644 (file)
@@ -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++) {