]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf ftrace: Fix hashmap__new() error checking
authorChen Ni <nichen@iscas.ac.cn>
Fri, 6 Mar 2026 04:10:52 +0000 (12:10 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 10 Mar 2026 14:53:27 +0000 (11:53 -0300)
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: 0f223813edd051a5 ("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>
tools/perf/builtin-ftrace.c

index 6b6eec65f93f5ce9d769669ca6d9a0829705e17a..4cc33452d79b626b0d6958177d1acbac121cdbbd 100644 (file)
@@ -18,6 +18,7 @@
 #include <poll.h>
 #include <ctype.h>
 #include <linux/capability.h>
+#include <linux/err.h>
 #include <linux/string.h>
 #include <sys/stat.h>
 
@@ -1209,8 +1210,12 @@ static int prepare_func_profile(struct perf_ftrace *ftrace)
        ftrace->graph_verbose = 0;
 
        ftrace->profile_hash = hashmap__new(profile_hash, profile_equal, NULL);
-       if (ftrace->profile_hash == NULL)
-               return -ENOMEM;
+       if (IS_ERR(ftrace->profile_hash)) {
+               int err = PTR_ERR(ftrace->profile_hash);
+
+               ftrace->profile_hash = NULL;
+               return err;
+       }
 
        return 0;
 }