[PATCH] perf annotate: Fix NULL vs IS_ERR() check in annotated_source__alloc_histograms()

Subsystems: performance events subsystem, the rest

STALE222d

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

[PATCH] perf annotate: Fix NULL vs IS_ERR() check in annotated_source__alloc_histograms()

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

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

Fixes: d3e7cad6f36d ("perf annotate: Add a hashmap for symbol histogram")
Signed-off-by: Chen Ni <redacted>
---
 tools/perf/util/annotate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2e3522905046..64ab5c36ac02 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,7 +138,7 @@ 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);
 
 	return src->histograms ? 0 : -1;
-- 
2.25.1

Re: [PATCH] perf annotate: Fix NULL vs IS_ERR() check in annotated_source__alloc_histograms()

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

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

Fixes: d3e7cad6f36d ("perf annotate: Add a hashmap for symbol histogram")
Signed-off-by: Chen Ni <redacted>
More on the ERR_PTR is a source of bugs..

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian
quoted hunk
---
 tools/perf/util/annotate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2e3522905046..64ab5c36ac02 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,7 +138,7 @@ 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);

        return src->histograms ? 0 : -1;
--
2.25.1

Re: [PATCH] perf annotate: Fix NULL vs IS_ERR() check in annotated_source__alloc_histograms()

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

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

Fixes: d3e7cad6f36d ("perf annotate: Add a hashmap for symbol histogram")
Signed-off-by: Chen Ni <redacted>
More on the ERR_PTR is a source of bugs..

Reviewed-by: Ian Rogers <irogers@google.com>

Thanks,
Ian
quoted
---
 tools/perf/util/annotate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 2e3522905046..64ab5c36ac02 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,7 +138,7 @@ 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))
Actually, should probably assign `src->samples = NULL;` here in case a
later read tries to use the ERR_PTR.

Thanks,
Ian
quoted
                zfree(&src->histograms);

        return src->histograms ? 0 : -1;
--
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