Commit 629eb703 authored by Colin Ian King's avatar Colin Ian King Committed by Ingo Molnar

perf/x86/intel/uncore: Fix memory leaks on allocation failures

Currently if an allocation fails then the error return paths
don't free up any currently allocated pmus[].boxes and pmus causing
a memory leak.  Add an error clean up exit path that frees these
objects.

Detected by CoverityScan, CID#711632 ("Resource Leak")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Acked-by: default avatarPeter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: kernel-janitors@vger.kernel.org
Fixes: 087bfbb0 ("perf/x86: Add generic Intel uncore PMU support")
Link: http://lkml.kernel.org/r/20171009172655.6132-1-colin.king@canonical.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent e6a52033
...@@ -822,7 +822,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) ...@@ -822,7 +822,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
pmus[i].type = type; pmus[i].type = type;
pmus[i].boxes = kzalloc(size, GFP_KERNEL); pmus[i].boxes = kzalloc(size, GFP_KERNEL);
if (!pmus[i].boxes) if (!pmus[i].boxes)
return -ENOMEM; goto err;
} }
type->pmus = pmus; type->pmus = pmus;
...@@ -836,7 +836,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) ...@@ -836,7 +836,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) + attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
sizeof(*attr_group), GFP_KERNEL); sizeof(*attr_group), GFP_KERNEL);
if (!attr_group) if (!attr_group)
return -ENOMEM; goto err;
attrs = (struct attribute **)(attr_group + 1); attrs = (struct attribute **)(attr_group + 1);
attr_group->name = "events"; attr_group->name = "events";
...@@ -849,7 +849,15 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) ...@@ -849,7 +849,15 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
} }
type->pmu_group = &uncore_pmu_attr_group; type->pmu_group = &uncore_pmu_attr_group;
return 0; return 0;
err:
for (i = 0; i < type->num_boxes; i++)
kfree(pmus[i].boxes);
kfree(pmus);
return -ENOMEM;
} }
static int __init static int __init
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment