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, tianyou.li@intel.com,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] perf annotate: Fix hashmap__new() error checking
Date: Tue, 10 Mar 2026 11:49:37 -0300 [thread overview]
Message-ID: <abAvgbIoWbpTRCQ2@x1> (raw)
In-Reply-To: <20260306035648.1266660-1-nichen@iscas.ac.cn>
On Fri, Mar 06, 2026 at 11:56:48AM +0800, Chen Ni wrote:
> The hashmap__new() function never returns NULL, it returns error
> pointers. Fix the error checking to match.
>
> Additionally, set src->samples to NULL to prevent any later code from
> accidentally using the error pointer.
>
> Fixes: d3e7cad6f36d ("perf annotate: Add a hashmap for symbol histogram")
> Reviewed-by: Ian Rogers <irogers@google.com>
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
Thanks, applied to perf-tools, for v7.0.
- Arnaldo
> ---
> Changes in v2:
> - Set src->samples to NULL on error
> - Update commit message
> ---
> tools/perf/util/annotate.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
> index 2e3522905046..63f0ee9d4c03 100644
> --- a/tools/perf/util/annotate.c
> +++ b/tools/perf/util/annotate.c
> @@ -44,6 +44,7 @@
> #include "strbuf.h"
> #include <regex.h>
> #include <linux/bitops.h>
> +#include <linux/err.h>
> #include <linux/kernel.h>
> #include <linux/string.h>
> #include <linux/zalloc.h>
> @@ -137,8 +138,10 @@ static int annotated_source__alloc_histograms(struct annotated_source *src,
> return -1;
>
> src->samples = hashmap__new(sym_hist_hash, sym_hist_equal, NULL);
> - if (src->samples == NULL)
> + if (IS_ERR(src->samples)) {
> zfree(&src->histograms);
> + src->samples = NULL;
> + }
>
> return src->histograms ? 0 : -1;
> }
> --
> 2.25.1
prev parent reply other threads:[~2026-03-10 14:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-06 3:56 [PATCH v2] perf annotate: Fix hashmap__new() error checking Chen Ni
2026-03-10 14:49 ` 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=abAvgbIoWbpTRCQ2@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 \
--cc=tianyou.li@intel.com \
/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