* [PATCH v2] perf ftrace: Fix hashmap__new() error checking
@ 2026-03-06 4:10 Chen Ni
2026-03-10 14:50 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: Chen Ni @ 2026-03-06 4:10 UTC (permalink / raw)
To: linux-perf-users
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark, linux-kernel, Chen Ni
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: 0f223813edd0 ("perf ftrace: Add 'profile' command")
Suggested-by: Ian Rogers <irogers@google.com>
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
Changes in v2:
- Set ftrace->profile_hash to NULL on error
- Return PTR_ERR(ftrace->profile_hash) instead of -ENOMEM
- Update commit message
---
tools/perf/builtin-ftrace.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 6b6eec65f93f..4cc33452d79b 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,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;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] perf ftrace: Fix hashmap__new() error checking
2026-03-06 4:10 [PATCH v2] perf ftrace: Fix hashmap__new() error checking Chen Ni
@ 2026-03-10 14:50 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-03-10 14:50 UTC (permalink / raw)
To: Chen Ni
Cc: linux-perf-users, peterz, mingo, namhyung, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
linux-kernel
On Fri, Mar 06, 2026 at 12:10:52PM +0800, Chen Ni wrote:
> 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().
Thanks, applied to perf-tools, for v7.0.
- Arnaldo
> Fixes: 0f223813edd0 ("perf ftrace: Add 'profile' command")
> Suggested-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
> Changes in v2:
> - Set ftrace->profile_hash to NULL on error
> - Return PTR_ERR(ftrace->profile_hash) instead of -ENOMEM
> - Update commit message
> ---
> tools/perf/builtin-ftrace.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
> index 6b6eec65f93f..4cc33452d79b 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,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;
> }
> --
> 2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-10 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 4:10 [PATCH v2] perf ftrace: Fix hashmap__new() error checking Chen Ni
2026-03-10 14:50 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox