Skip to content

Commit

Permalink
perf/x86/intel: Fix memory leak on hot-plug allocation fail
Browse files Browse the repository at this point in the history
We fail to free the shared_regs allocation if the constraint_list
allocation fails.

Cure this and be more consistent in NULL-ing the pointers after free.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Aug 12, 2015
1 parent c7999c6 commit dbc72b7
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions arch/x86/kernel/cpu/perf_event_intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2534,26 +2534,35 @@ static int intel_pmu_cpu_prepare(int cpu)
if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
cpuc->shared_regs = allocate_shared_regs(cpu);
if (!cpuc->shared_regs)
return NOTIFY_BAD;
goto err;
}

if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
size_t sz = X86_PMC_IDX_MAX * sizeof(struct event_constraint);

cpuc->constraint_list = kzalloc(sz, GFP_KERNEL);
if (!cpuc->constraint_list)
return NOTIFY_BAD;
goto err_shared_regs;

cpuc->excl_cntrs = allocate_excl_cntrs(cpu);
if (!cpuc->excl_cntrs) {
kfree(cpuc->constraint_list);
kfree(cpuc->shared_regs);
return NOTIFY_BAD;
}
if (!cpuc->excl_cntrs)
goto err_constraint_list;

cpuc->excl_thread_id = 0;
}

return NOTIFY_OK;

err_constraint_list:
kfree(cpuc->constraint_list);
cpuc->constraint_list = NULL;

err_shared_regs:
kfree(cpuc->shared_regs);
cpuc->shared_regs = NULL;

err:
return NOTIFY_BAD;
}

static void intel_pmu_cpu_starting(int cpu)
Expand Down

0 comments on commit dbc72b7

Please sign in to comment.