Skip to content

Commit 7e512f5

Browse files
dhananjay-AMDIngo Molnar
authored andcommitted
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: 9b99d65 ("perf/x86/rapl: Move the pmu allocation out of CPU hotplug") Signed-off-by: Dhananjay Ugwekar <dhananjay.ugwekar@amd.com> Signed-off-by: Ingo Molnar <mingo@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20250320100617.4480-1-dhananjay.ugwekar@amd.com
1 parent 65a9926 commit 7e512f5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

arch/x86/events/rapl.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ static int __init init_rapl_pmus(struct rapl_pmus **rapl_pmus_ptr, int rapl_pmu_
730730
{
731731
int nr_rapl_pmu = topology_max_packages();
732732
struct rapl_pmus *rapl_pmus;
733+
int ret;
733734

734735
/*
735736
* 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_
761762
rapl_pmus->pmu.module = THIS_MODULE;
762763
rapl_pmus->pmu.capabilities = PERF_PMU_CAP_NO_EXCLUDE;
763764

764-
return init_rapl_pmu(rapl_pmus);
765+
ret = init_rapl_pmu(rapl_pmus);
766+
if (ret)
767+
kfree(rapl_pmus);
768+
769+
return ret;
765770
}
766771

767772
static struct rapl_model model_snb = {

0 commit comments

Comments
 (0)