* [PATCH v2] perf annotate: Fix hashmap__new() error checking
@ 2026-03-06 3:56 Chen Ni
2026-03-10 14:49 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 2+ messages in thread
From: Chen Ni @ 2026-03-06 3:56 UTC (permalink / raw)
To: linux-perf-users
Cc: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin,
jolsa, irogers, adrian.hunter, james.clark, tianyou.li,
linux-kernel, Chen Ni
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>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] perf annotate: Fix hashmap__new() error checking
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
0 siblings, 0 replies; 2+ messages in thread
From: Arnaldo Carvalho de Melo @ 2026-03-10 14:49 UTC (permalink / raw)
To: Chen Ni
Cc: linux-perf-users, peterz, mingo, namhyung, mark.rutland,
alexander.shishkin, jolsa, irogers, adrian.hunter, james.clark,
tianyou.li, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-10 14:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox