public inbox for linux-perf-users@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Chen Ni <nichen@iscas.ac.cn>
Cc: linux-perf-users@vger.kernel.org, peterz@infradead.org,
	mingo@redhat.com, namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	james.clark@linaro.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] perf ftrace: Fix hashmap__new() error checking
Date: Tue, 10 Mar 2026 11:50:30 -0300	[thread overview]
Message-ID: <abAvtphCy_MWy7Br@x1> (raw)
In-Reply-To: <20260306041052.1266836-1-nichen@iscas.ac.cn>

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

      reply	other threads:[~2026-03-10 14:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abAvtphCy_MWy7Br@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=nichen@iscas.ac.cn \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox