From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932383AbdJJPAg (ORCPT ); Tue, 10 Oct 2017 11:00:36 -0400 Received: from terminus.zytor.com ([65.50.211.136]:40673 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932367AbdJJPAd (ORCPT ); Tue, 10 Oct 2017 11:00:33 -0400 Date: Tue, 10 Oct 2017 07:56:50 -0700 From: tip-bot for Colin Ian King Message-ID: Cc: torvalds@linux-foundation.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, hpa@zytor.com, colin.king@canonical.com, mingo@kernel.org, peterz@infradead.org Reply-To: mingo@kernel.org, peterz@infradead.org, hpa@zytor.com, colin.king@canonical.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org In-Reply-To: <20171009172655.6132-1-colin.king@canonical.com> References: <20171009172655.6132-1-colin.king@canonical.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf/x86/intel/uncore: Fix memory leaks on allocation failures Git-Commit-ID: 629eb703d3e46aa570c6c91235d38fd09ed8c58b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 629eb703d3e46aa570c6c91235d38fd09ed8c58b Gitweb: https://git.kernel.org/tip/629eb703d3e46aa570c6c91235d38fd09ed8c58b Author: Colin Ian King AuthorDate: Mon, 9 Oct 2017 18:26:55 +0100 Committer: Ingo Molnar CommitDate: Tue, 10 Oct 2017 12:51:07 +0200 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 Acked-by: Peter Zijlstra Cc: Linus Torvalds Cc: Thomas Gleixner Cc: kernel-janitors@vger.kernel.org Fixes: 087bfbb03269 ("perf/x86: Add generic Intel uncore PMU support") Link: http://lkml.kernel.org/r/20171009172655.6132-1-colin.king@canonical.com Signed-off-by: Ingo Molnar --- arch/x86/events/intel/uncore.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/intel/uncore.c b/arch/x86/events/intel/uncore.c index 1c5390f..d45e063 100644 --- a/arch/x86/events/intel/uncore.c +++ b/arch/x86/events/intel/uncore.c @@ -822,7 +822,7 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) pmus[i].type = type; pmus[i].boxes = kzalloc(size, GFP_KERNEL); if (!pmus[i].boxes) - return -ENOMEM; + goto err; } type->pmus = pmus; @@ -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) + sizeof(*attr_group), GFP_KERNEL); if (!attr_group) - return -ENOMEM; + goto err; attrs = (struct attribute **)(attr_group + 1); attr_group->name = "events"; @@ -849,7 +849,15 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid) } type->pmu_group = &uncore_pmu_attr_group; + return 0; + +err: + for (i = 0; i < type->num_boxes; i++) + kfree(pmus[i].boxes); + kfree(pmus); + + return -ENOMEM; } static int __init