Skip to content

Commit 7ad1437

Browse files
committed
perf/x86/intel: Plug memory leak in intel_pmu_init()
A recent commit introduced an extra merge_attr() call in the skylake branch, which causes a memory leak. Store the pointer to the extra allocated memory and free it at the end of the function. Fixes: a5df70c ("perf/x86: Only show format attributes when supported") Reported-by: Tommi Rantala <tommi.t.rantala@nokia.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andi Kleen <ak@linux.intel.com>
1 parent 2e36463 commit 7ad1437

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

arch/x86/events/intel/core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3847,14 +3847,15 @@ static struct attribute *intel_pmu_attrs[] = {
38473847

38483848
__init int intel_pmu_init(void)
38493849
{
3850+
struct attribute **extra_attr = NULL;
3851+
struct attribute **to_free = NULL;
38503852
union cpuid10_edx edx;
38513853
union cpuid10_eax eax;
38523854
union cpuid10_ebx ebx;
38533855
struct event_constraint *c;
38543856
unsigned int unused;
38553857
struct extra_reg *er;
38563858
int version, i;
3857-
struct attribute **extra_attr = NULL;
38583859
char *name;
38593860

38603861
if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
@@ -4294,6 +4295,7 @@ __init int intel_pmu_init(void)
42944295
extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
42954296
hsw_format_attr : nhm_format_attr;
42964297
extra_attr = merge_attr(extra_attr, skl_format_attr);
4298+
to_free = extra_attr;
42974299
x86_pmu.cpu_events = get_hsw_events_attrs();
42984300
intel_pmu_pebs_data_source_skl(
42994301
boot_cpu_data.x86_model == INTEL_FAM6_SKYLAKE_X);
@@ -4401,6 +4403,7 @@ __init int intel_pmu_init(void)
44014403
pr_cont("full-width counters, ");
44024404
}
44034405

4406+
kfree(to_free);
44044407
return 0;
44054408
}
44064409

0 commit comments

Comments
 (0)