Skip to content

Commit 629eb70

Browse files
Colin Ian KingIngo Molnar
authored andcommitted
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: Colin Ian King <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Fixes: 087bfbb ("perf/x86: Add generic Intel uncore PMU support") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent e6a5203 commit 629eb70

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
822822
pmus[i].type = type;
823823
pmus[i].boxes = kzalloc(size, GFP_KERNEL);
824824
if (!pmus[i].boxes)
825-
return -ENOMEM;
825+
goto err;
826826
}
827827

828828
type->pmus = pmus;
@@ -836,7 +836,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
836836
attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
837837
sizeof(*attr_group), GFP_KERNEL);
838838
if (!attr_group)
839-
return -ENOMEM;
839+
goto err;
840840

841841
attrs = (struct attribute **)(attr_group + 1);
842842
attr_group->name = "events";
@@ -849,7 +849,15 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
849849
}
850850

851851
type->pmu_group = &uncore_pmu_attr_group;
852+
852853
return 0;
854+
855+
err:
856+
for (i = 0; i < type->num_boxes; i++)
857+
kfree(pmus[i].boxes);
858+
kfree(pmus);
859+
860+
return -ENOMEM;
853861
}
854862

855863
static int __init

0 commit comments

Comments
 (0)