Skip to contentSkip to conversation

perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init

PATCH In review Miaoqian Lin 3 participants 3 messages Aug 5, 2025 – Aug 18, 2025 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: pmu: Fix IS_ERR() vs NULL check bug in perf_pmu__init

Replace NULL check with IS_ERR() check after calling hashmap__new() since this function return error pointers (ERR_PTR). Using NULL check could lead to invalid pointer dereference.

Fixes 754baf426e09 ("perf pmu: Change aliases from list to hashmap")
---
 tools/perf/util/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/pmu.c +1 -1
index 5a291f1380ed..da6f05872493 100644
@@ -1176,7 +1176,7 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
 		return -ENOMEM;
 
 	pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
-	if (!pmu->aliases)
+	if (IS_ERR(pmu->aliases))
 		return -ENOMEM;
 
 	return 0;
Signature · 1 line
2.25.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 6 lines · Miaoqian Lin

Replace NULL check with IS_ERR() check after calling hashmap__new() since this function return error pointers (ERR_PTR). Using NULL check could lead to invalid pointer dereference.

Fixes 754baf426e09 ("perf pmu: Change aliases from list to hashmap")

Thanks,
Namhyung

Quoted 20 lines
---
 tools/perf/util/pmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/pmu.c +1 -1
index 5a291f1380ed..da6f05872493 100644
@@ -1176,7 +1176,7 @@ int perf_pmu__init(struct perf_pmu *pmu, __u32 type, const char *name)
 		return -ENOMEM;
 
 	pmu->aliases = hashmap__new(aliases__hash, aliases__equal, /*ctx=*/ NULL);
-	if (!pmu->aliases)
+	if (IS_ERR(pmu->aliases))
 		return -ENOMEM;
 
 	return 0;
Signature · 1 line
2.25.1
reviewer Reviewed-by
#2 lore raw
Quoted 4 lines · Namhyung Kim

Hello,

On Tue, Aug 05, 2025 at 10:32:07AM +0400, Miaoqian Lin wrote:

Quoted 8 lines
Quoted 6 lines

Replace NULL check with IS_ERR() check after calling hashmap__new() since this function return error pointers (ERR_PTR). Using NULL check could lead to invalid pointer dereference.

Fixes 754baf426e09 ("perf pmu: Change aliases from list to hashmap")

Thanks,
Ian