NACK/Cmnt: [SRU][N][PATCH 2/2] libperf cpumap: Ensure empty cpumap is NULL from alloc

Manuel Diewald manuel.diewald at canonical.com
Mon Apr 14 15:45:21 UTC 2025


On Mon, Apr 14, 2025 at 05:38:21PM +0300, Mehmet Basaran wrote:
> From: Ian Rogers <irogers at google.com>
> 

Both patches are missing the BugLink that needs to be inserted here.

> Potential corner cases could cause a cpumap to be allocated with size
> 0, but an empty cpumap should be represented as NULL. Add a path in
> perf_cpu_map__alloc() to ensure this.
> 
> Suggested-by: James Clark <james.clark at arm.com>
> Signed-off-by: Ian Rogers <irogers at google.com>
> Acked-by: Namhyung Kim <namhyung at kernel.org>
> Cc: Adrian Hunter <adrian.hunter at intel.com>
> Cc: Alexander Shishkin <alexander.shishkin at linux.intel.com>
> Cc: Alexandre Ghiti <alexghiti at rivosinc.com>
> Cc: Andrew Jones <ajones at ventanamicro.com>
> Cc: André Almeida <andrealmeid at igalia.com>
> Cc: Athira Rajeev <atrajeev at linux.vnet.ibm.com>
> Cc: Atish Patra <atishp at rivosinc.com>
> Cc: Changbin Du <changbin.du at huawei.com>
> Cc: Darren Hart <dvhart at infradead.org>
> Cc: Davidlohr Bueso <dave at stgolabs.net>
> Cc: Huacai Chen <chenhuacai at kernel.org>
> Cc: Ingo Molnar <mingo at redhat.com>
> Cc: Jiri Olsa <jolsa at kernel.org>
> Cc: John Garry <john.g.garry at oracle.com>
> Cc: K Prateek Nayak <kprateek.nayak at amd.com>
> Cc: Kajol Jain <kjain at linux.ibm.com>
> Cc: Kan Liang <kan.liang at linux.intel.com>
> Cc: Leo Yan <leo.yan at linaro.org>
> Cc: Mark Rutland <mark.rutland at arm.com>
> Cc: Mike Leach <mike.leach at linaro.org>
> Cc: Nick Desaulniers <ndesaulniers at google.com>
> Cc: Paolo Bonzini <pbonzini at redhat.com>
> Cc: Paran Lee <p4ranlee at gmail.com>
> Cc: Peter Zijlstra <peterz at infradead.org>
> Cc: Ravi Bangoria <ravi.bangoria at amd.com>
> Cc: Sandipan Das <sandipan.das at amd.com>
> Cc: Sean Christopherson <seanjc at google.com>
> Cc: Steinar H. Gunderson <sesse at google.com>
> Cc: Suzuki Poulouse <suzuki.poulose at arm.com>
> Cc: Thomas Gleixner <tglx at linutronix.de>
> Cc: Will Deacon <will at kernel.org>
> Cc: Yang Jihong <yangjihong1 at huawei.com>
> Cc: Yang Li <yang.lee at linux.alibaba.com>
> Cc: Yanteng Si <siyanteng at loongson.cn>
> Closes: https://lore.kernel.org/lkml/2cd09e7c-eb88-6726-6169-647dcd0a8101@arm.com/
> Link: https://lore.kernel.org/r/20240202234057.2085863-3-irogers@google.com
> Signed-off-by: Arnaldo Carvalho de Melo <acme at redhat.com>
> (cherry picked from commit 98d02d314fe5e42c674270209281ca333e70c158 linux-6.12.y)

I can't find that commit upstream, it doesn't seem to be on stable
linux-6.12.y.

> Signed-off-by: Mehmet Basaran <mehmet.basaran at canonical.com>
> ---
>  tools/lib/perf/cpumap.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c
> index ba49552952c5..cae799ad44e1 100644
> --- a/tools/lib/perf/cpumap.c
> +++ b/tools/lib/perf/cpumap.c
> @@ -18,9 +18,13 @@ void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus)
>  
>  struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus)
>  {
> -	RC_STRUCT(perf_cpu_map) *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus);
> +	RC_STRUCT(perf_cpu_map) *cpus;
>  	struct perf_cpu_map *result;
>  
> +	if (nr_cpus == 0)
> +		return NULL;
> +
> +	cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus);
>  	if (ADD_RC_CHK(result, cpus)) {
>  		cpus->nr = nr_cpus;
>  		refcount_set(&cpus->refcnt, 1);
> -- 
> 2.43.0
> 
> 
> -- 
> kernel-team mailing list
> kernel-team at lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/kernel-team

Please insert BugLinks and fix the provenance of this patch.

-- 
 Manuel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.ubuntu.com/archives/kernel-team/attachments/20250414/4d81baff/attachment.sig>


More information about the kernel-team mailing list