Skip to contentSkip to conversation

perf/x86/rapl: Fix error handling in init_rapl_pmus

PATCH Applied Dhananjay Ugwekar 2 participants 2 messages Mar 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/x86/rapl: Fix error handling in init_rapl_pmus

If init_rapl_pmu() fails while allocating memory for "rapl_pmu" objects, we miss freeing the "rapl_pmus" object in the error path. Fix that.

Fixes 9b99d65c0bb4 ("perf/x86/rapl: Move the pmu allocation out of CPU hotplug")
---
 arch/x86/events/rapl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/events/rapl.c +6 -1
index 6941f4811bec..043f0a0b1e00 100644
@@ -730,6 +730,7 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
 {
 	int nr_rapl_pmu = topology_max_packages();
 	struct rapl_pmus *rapl_pmus;
+	int ret;
 
 	/*
 	 * rapl_pmu_scope must be either PKG, DIE or CORE
@@ -761,7 +762,11 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
 	rapl_pmus->pmu.module		= THIS_MODULE;
 	rapl_pmus->pmu.capabilities	= PERF_PMU_CAP_NO_EXCLUDE;
 
-	return init_rapl_pmu(rapl_pmus);
+	ret = init_rapl_pmu(rapl_pmus);
+	if (ret)
+		kfree(rapl_pmus);
+
+	return ret;
 }
 
 static struct rapl_model model_snb = {
Signature · 1 line
2.34.1
#1 lore raw

[tip: perf/urgent] perf/x86/rapl: Fix error handling in init_rapl_pmus()

The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     7e512f5ad24458e2c930b5be5d96ddf9e176e05d
Gitweb:        https://git.kernel.org/tip/7e512f5ad24458e2c930b5be5d96ddf9e176e05d
Author:        Dhananjay Ugwekar <[email protected]>
AuthorDate:    Thu, 20 Mar 2025 10:06:19 
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Thu, 20 Mar 2025 21:03:55 +01:00

perf/x86/rapl: Fix error handling in init_rapl_pmus()

If init_rapl_pmu() fails while allocating memory for "rapl_pmu" objects, we miss freeing the "rapl_pmus" object in the error path. Fix that.

Fixes 9b99d65c0bb4 ("perf/x86/rapl: Move the pmu allocation out of CPU hotplug")
Cc Peter Zijlstra <[email protected]>
---
 arch/x86/events/rapl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/events/rapl.c +6 -1
index 6941f48..043f0a0 100644
@@ -730,6 +730,7 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
 {
 	int nr_rapl_pmu = topology_max_packages();
 	struct rapl_pmus *rapl_pmus;
+	int ret;
 
 	/*
 	 * rapl_pmu_scope must be either PKG, DIE or CORE
@@ -761,7 +762,11 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
 	rapl_pmus->pmu.module		= THIS_MODULE;
 	rapl_pmus->pmu.capabilities	= PERF_PMU_CAP_NO_EXCLUDE;
 
-	return init_rapl_pmu(rapl_pmus);
+	ret = init_rapl_pmu(rapl_pmus);
+	if (ret)
+		kfree(rapl_pmus);
+
+	return ret;
 }
 
 static struct rapl_model model_snb = {