Skip to content

Commit

Permalink
perf annotate-data: Ensure the number of type histograms
Browse files Browse the repository at this point in the history
Arnaldo reported that there is a case where nr_histograms and histograms
don't agree each other.

It ended up in a segfault trying to access a NULL histograms array.

Let's make sure to update the nr_histograms when the histograms array is
changed.

Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20240510210452.2449944-2-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Namhyung Kim authored and Arnaldo Carvalho de Melo committed May 11, 2024
1 parent 9ef3026 commit 2af1280
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/perf/util/annotate-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,6 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en
sz += sizeof(struct type_hist_entry) * adt->self.size;

/* Allocate a table of pointers for each event */
adt->nr_histograms = nr_entries;
adt->histograms = calloc(nr_entries, sizeof(*adt->histograms));
if (adt->histograms == NULL)
return -ENOMEM;
Expand All @@ -1814,6 +1813,8 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en
if (adt->histograms[i] == NULL)
goto err;
}

adt->nr_histograms = nr_entries;
return 0;

err:
Expand All @@ -1827,7 +1828,9 @@ static void delete_data_type_histograms(struct annotated_data_type *adt)
{
for (int i = 0; i < adt->nr_histograms; i++)
zfree(&(adt->histograms[i]));

zfree(&adt->histograms);
adt->nr_histograms = 0;
}

void annotated_data_type__tree_delete(struct rb_root *root)
Expand Down

0 comments on commit 2af1280

Please sign in to comment.