Skip to content

Commit b7b4839

Browse files
Dave JonesIngo Molnar
authored andcommitted
perf/x86: Fix leak in uncore_type_init failure paths
The error path of uncore_type_init() frees up any allocations that were made along the way, but it relies upon type->pmus being set, which only happens if the function succeeds. As type->pmus remains null in this case, the call to uncore_type_exit will do nothing. Moving the assignment earlier will allow us to actually free those allocations should something go awry. Signed-off-by: Dave Jones <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent b8ad0f9 commit b7b4839

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

arch/x86/kernel/cpu/perf_event_intel_uncore.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,8 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
33343334
if (!pmus)
33353335
return -ENOMEM;
33363336

3337+
type->pmus = pmus;
3338+
33373339
type->unconstrainted = (struct event_constraint)
33383340
__EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1,
33393341
0, type->num_counters, 0, 0);
@@ -3369,7 +3371,6 @@ static int __init uncore_type_init(struct intel_uncore_type *type)
33693371
}
33703372

33713373
type->pmu_group = &uncore_pmu_attr_group;
3372-
type->pmus = pmus;
33733374
return 0;
33743375
fail:
33753376
uncore_type_exit(type);

0 commit comments

Comments
 (0)