[PATCH] perf ftrace: Fix NULL vs IS_ERR() check in prepare_func_profile()

Subsystems: performance events subsystem, the rest

STALE226d

2 messages, 2 authors, 2026-03-05 · open the first message on its own page

[PATCH] perf ftrace: Fix NULL vs IS_ERR() check in prepare_func_profile()

From: Chen Ni <hidden>
Date: 2026-03-05 02:25:18

The hashmap__new() function never returns NULL, it returns error
pointers. Fix the error checking to match.

Fixes: 0f223813edd0 ("perf ftrace: Add 'profile' command")
Signed-off-by: Chen Ni <redacted>
---
 tools/perf/builtin-ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 6b6eec65f93f..9e7e81a08606 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -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,7 +1210,7 @@ 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)
+	if (IS_ERR(ftrace->profile_hash))
 		return -ENOMEM;
 
 	return 0;
-- 
2.25.1

Re: [PATCH] perf ftrace: Fix NULL vs IS_ERR() check in prepare_func_profile()

From: Ian Rogers <irogers@google.com>
Date: 2026-03-05 22:31:35

On Wed, Mar 4, 2026 at 6:25 PM Chen Ni [off-list ref] wrote:
quoted hunk
The hashmap__new() function never returns NULL, it returns error
pointers. Fix the error checking to match.

Fixes: 0f223813edd0 ("perf ftrace: Add 'profile' command")
Signed-off-by: Chen Ni <redacted>
---
 tools/perf/builtin-ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 6b6eec65f93f..9e7e81a08606 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -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,7 +1210,7 @@ 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)
+       if (IS_ERR(ftrace->profile_hash))
                return -ENOMEM;
It's probably a good idea to make sure ftrace->profile_hash is NULL
here. It is probably more correct to return an PTR_ERR of the return
value from hashmap__new.

Thanks,
Ian
        return 0;
--
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help