Skip to content

Commit bf29cb3

Browse files
Chen Niacmel
authored andcommitted
perf annotate: Fix hashmap__new() error checking
The hashmap__new() function never returns NULL, it returns error pointers. Fix the error checking to match. Additionally, set src->samples to NULL to prevent any later code from accidentally using the error pointer. Fixes: d3e7cad ("perf annotate: Add a hashmap for symbol histogram") Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Chen Ni <nichen@iscas.ac.cn> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: James Clark <james.clark@linaro.org> 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: Tianyou Li <tianyou.li@intel.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent e374193 commit bf29cb3

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

tools/perf/util/annotate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "strbuf.h"
4545
#include <regex.h>
4646
#include <linux/bitops.h>
47+
#include <linux/err.h>
4748
#include <linux/kernel.h>
4849
#include <linux/string.h>
4950
#include <linux/zalloc.h>
@@ -137,8 +138,10 @@ static int annotated_source__alloc_histograms(struct annotated_source *src,
137138
return -1;
138139

139140
src->samples = hashmap__new(sym_hist_hash, sym_hist_equal, NULL);
140-
if (src->samples == NULL)
141+
if (IS_ERR(src->samples)) {
141142
zfree(&src->histograms);
143+
src->samples = NULL;
144+
}
142145

143146
return src->histograms ? 0 : -1;
144147
}

0 commit comments

Comments
 (0)