Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754829AbcCBXx1 (ORCPT ); Wed, 2 Mar 2016 18:53:27 -0500 Received: from mga02.intel.com ([134.134.136.20]:5695 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753016AbcCBXx0 (ORCPT ); Wed, 2 Mar 2016 18:53:26 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,531,1449561600"; d="scan'208";a="58728252" From: Vikas Shivappa To: vikas.shivappa@intel.com, vikas.shivappa@linux.intel.com Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@kernel.org, peterz@infradead.org, ravi.v.shankar@intel.com, tony.luck@intel.com, fenghua.yu@intel.com, h.peter.anvin@intel.com Subject: Re: [PATCH 2/6] x86,perf/cqm: Fix cqm memory leak and notifier leak Date: Wed, 2 Mar 2016 15:53:59 -0800 Message-Id: <1456962839-29170-1-git-send-email-vikas.shivappa@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456876108-28770-3-git-send-email-vikas.shivappa@linux.intel.com> References: <1456876108-28770-3-git-send-email-vikas.shivappa@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1948 Lines: 84 Fixes the hotcpu notifier leak and other global variable memory leaks during cqm(cache quality of service monitoring) initialization. Reviewed-by: Tony Luck Signed-off-by: Vikas Shivappa --- Fixed the memory leak for cqm_rmid_ptrs as per Thomas feedback. arch/x86/kernel/cpu/perf_event_intel_cqm.c | 34 ++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu/perf_event_intel_cqm.c b/arch/x86/kernel/cpu/perf_event_intel_cqm.c index e6be335..37a93fa 100644 --- a/arch/x86/kernel/cpu/perf_event_intel_cqm.c +++ b/arch/x86/kernel/cpu/perf_event_intel_cqm.c @@ -250,10 +250,13 @@ static int intel_cqm_setup_rmid_cache(void) return 0; fail: - while (r--) + while (r--) { kfree(cqm_rmid_ptrs[r]); + cqm_rmid_ptrs[r] = NULL; + } kfree(cqm_rmid_ptrs); + cqm_rmid_ptrs = NULL; return -ENOMEM; } @@ -1320,9 +1323,19 @@ static const struct x86_cpu_id intel_cqm_match[] = { {} }; +static void cqm_cleanup(void) +{ + int r = cqm_max_rmid; + + while (r--) + kfree(cqm_rmid_ptrs[r]); + + kfree(cqm_rmid_ptrs); +} + static int __init intel_cqm_init(void) { - char *str, scale[20]; + char *str = NULL, scale[20]; int i, cpu, ret; if (!x86_match_cpu(intel_cqm_match)) @@ -1382,16 +1395,25 @@ static int __init intel_cqm_init(void) cqm_pick_event_reader(i); } - __perf_cpu_notifier(intel_cqm_cpu_notifier); - ret = perf_pmu_register(&intel_cqm_pmu, "intel_cqm", -1); - if (ret) + if (ret) { pr_err("Intel CQM perf registration failed: %d\n", ret); - else + goto out; + } else { pr_info("Intel CQM monitoring enabled\n"); + } + /* + * Register the hot cpu notifier once we are sure cqm + * is enabled to avoid notifier leak. + */ + __perf_cpu_notifier(intel_cqm_cpu_notifier); out: cpu_notifier_register_done(); + if (ret) { + kfree(str); + cqm_cleanup(); + } return ret; } -- 1.9.1