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 <davej@fedoraproject.org>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20140306172028.GA552@redhat.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Dave Jones and committed by
Ingo Molnar
b7b4839d b8ad0f91

+2 -1
+2 -1
arch/x86/kernel/cpu/perf_event_intel_uncore.c
··· 3334 if (!pmus) 3335 return -ENOMEM; 3336 3337 type->unconstrainted = (struct event_constraint) 3338 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1, 3339 0, type->num_counters, 0, 0); ··· 3371 } 3372 3373 type->pmu_group = &uncore_pmu_attr_group; 3374 - type->pmus = pmus; 3375 return 0; 3376 fail: 3377 uncore_type_exit(type);
··· 3334 if (!pmus) 3335 return -ENOMEM; 3336 3337 + type->pmus = pmus; 3338 + 3339 type->unconstrainted = (struct event_constraint) 3340 __EVENT_CONSTRAINT(0, (1ULL << type->num_counters) - 1, 3341 0, type->num_counters, 0, 0); ··· 3369 } 3370 3371 type->pmu_group = &uncore_pmu_attr_group; 3372 return 0; 3373 fail: 3374 uncore_type_exit(type);