Skip to content

Commit

Permalink
perf/x86/rapl: Fix error handling in init_rapl_pmus()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Dhananjay Ugwekar authored and Ingo Molnar committed Mar 20, 2025
1 parent 65a9926 commit 7e512f5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion arch/x86/events/rapl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 7e512f5

Please sign in to comment.