提交 dbc72b7a 编写于 作者: P Peter Zijlstra 提交者: Ingo Molnar

perf/x86/intel: Fix memory leak on hot-plug allocation fail

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: NPeter 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: NIngo Molnar <mingo@kernel.org>
上级 c7999c6f
...@@ -2534,7 +2534,7 @@ static int intel_pmu_cpu_prepare(int cpu) ...@@ -2534,7 +2534,7 @@ static int intel_pmu_cpu_prepare(int cpu)
if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) { if (x86_pmu.extra_regs || x86_pmu.lbr_sel_map) {
cpuc->shared_regs = allocate_shared_regs(cpu); cpuc->shared_regs = allocate_shared_regs(cpu);
if (!cpuc->shared_regs) if (!cpuc->shared_regs)
return NOTIFY_BAD; goto err;
} }
if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) { if (x86_pmu.flags & PMU_FL_EXCL_CNTRS) {
...@@ -2542,18 +2542,27 @@ static int intel_pmu_cpu_prepare(int cpu) ...@@ -2542,18 +2542,27 @@ static int intel_pmu_cpu_prepare(int cpu)
cpuc->constraint_list = kzalloc(sz, GFP_KERNEL); cpuc->constraint_list = kzalloc(sz, GFP_KERNEL);
if (!cpuc->constraint_list) if (!cpuc->constraint_list)
return NOTIFY_BAD; goto err_shared_regs;
cpuc->excl_cntrs = allocate_excl_cntrs(cpu); cpuc->excl_cntrs = allocate_excl_cntrs(cpu);
if (!cpuc->excl_cntrs) { if (!cpuc->excl_cntrs)
kfree(cpuc->constraint_list); goto err_constraint_list;
kfree(cpuc->shared_regs);
return NOTIFY_BAD;
}
cpuc->excl_thread_id = 0; cpuc->excl_thread_id = 0;
} }
return NOTIFY_OK; 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) static void intel_pmu_cpu_starting(int cpu)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册