int (*f)(struct perf_cpu_map *map, int cpu, void *data),
void *data)
{
- struct perf_cpu_map *c;
int nr = cpus->nr;
+ struct perf_cpu_map *c = perf_cpu_map__empty_new(nr);
int cpu, s1, s2;
- /* allocate as much as possible */
- c = calloc(1, sizeof(*c) + nr * sizeof(int));
if (!c)
return -1;
+ /* Reset size as it may only be partially filled */
+ c->nr = 0;
+
for (cpu = 0; cpu < nr; cpu++) {
s1 = f(cpus, cpu, data);
for (s2 = 0; s2 < c->nr; s2++) {
/* ensure we process id in increasing order */
qsort(c->map, c->nr, sizeof(int), cmp_ids);
- refcount_set(&c->refcnt, 1);
*res = c;
return 0;
}