Re: [PATCH v7 2/5] perf cpumap: Add reference count checking

From: Arnaldo Carvalho de Melo
Date: Wed Apr 12 2023 - 11:50:14 EST


Em Tue, Apr 11, 2023 at 03:19:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Apr 07, 2023 at 04:04:02PM -0700, Ian Rogers escreveu:
> > This change is intended to catch:
> > - use after put: using a cpumap after you have put it will cause a
> > segv.
> > - unbalanced puts: two puts for a get will result in a double free
> > that can be captured and reported by tools like address sanitizer,
> > including with the associated stack traces of allocation and frees.
> > - missing puts: if a put is missing then the get turns into a memory
> > leak that can be reported by leak sanitizer, including the stack
> > trace at the point the get occurs.

> I think this should be further split into self contained patches as it
> does:

> These are missing convertions that should be in a separate patch, no?
>
> > @@ -239,7 +236,7 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus,
> > {
> > int idx;
> > struct perf_cpu cpu;
> > - struct cpu_aggr_map *c = cpu_aggr_map__empty_new(cpus->nr);
> > + struct cpu_aggr_map *c = cpu_aggr_map__empty_new(perf_cpu_map__nr(cpus));
> >
> > if (!c)
> > return NULL;

Extracted this from your larger patch: