Skip to content

Commit be34705

Browse files
Chen Niacmel
authored andcommitted
perf ftrace: Fix hashmap__new() error checking
The hashmap__new() function never returns NULL, it returns error pointers. Fix the error checking to match. Additionally, set ftrace->profile_hash to NULL on error, and return the exact error code from hashmap__new(). Fixes: 0f22381 ("perf ftrace: Add 'profile' command") Suggested-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> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent bf29cb3 commit be34705

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

tools/perf/builtin-ftrace.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <poll.h>
1919
#include <ctype.h>
2020
#include <linux/capability.h>
21+
#include <linux/err.h>
2122
#include <linux/string.h>
2223
#include <sys/stat.h>
2324

@@ -1209,8 +1210,12 @@ static int prepare_func_profile(struct perf_ftrace *ftrace)
12091210
ftrace->graph_verbose = 0;
12101211

12111212
ftrace->profile_hash = hashmap__new(profile_hash, profile_equal, NULL);
1212-
if (ftrace->profile_hash == NULL)
1213-
return -ENOMEM;
1213+
if (IS_ERR(ftrace->profile_hash)) {
1214+
int err = PTR_ERR(ftrace->profile_hash);
1215+
1216+
ftrace->profile_hash = NULL;
1217+
return err;
1218+
}
12141219

12151220
return 0;
12161221
}

0 commit comments

Comments
 (0)