From patchwork Wed Aug 18 01:27:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leann Ogasawara X-Patchwork-Id: 61981 X-Patchwork-Delegate: leann.ogasawara@canonical.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id A1E20B70E1 for ; Wed, 18 Aug 2010 11:27:37 +1000 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OlXRD-00052Q-6R; Wed, 18 Aug 2010 02:27:31 +0100 Received: from adelie.canonical.com ([91.189.90.139]) by chlorine.canonical.com with esmtp (Exim 4.69) (envelope-from ) id 1OlXRA-00050q-FS for kernel-team@lists.ubuntu.com; Wed, 18 Aug 2010 02:27:28 +0100 Received: from hutte.canonical.com ([91.189.90.181]) by adelie.canonical.com with esmtp (Exim 4.69 #1 (Debian)) id 1OlXRA-0006LX-1L for ; Wed, 18 Aug 2010 02:27:28 +0100 Received: from c-76-105-148-120.hsd1.or.comcast.net ([76.105.148.120] helo=localhost) by hutte.canonical.com with esmtpsa (TLS-1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1OlXR9-0001tC-K0 for kernel-team@lists.ubuntu.com; Wed, 18 Aug 2010 02:27:28 +0100 From: leann.ogasawara@canonical.com To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/6] X86: intel_ips, check for kzalloc properly Date: Tue, 17 Aug 2010 18:27:08 -0700 Message-Id: <9b71ef9de4680145fd9eaf45c9a08a38a4748c11.1282089274.git.leann.ogasawara@canonical.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: In-Reply-To: References: X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: kernel-team-bounces@lists.ubuntu.com Errors-To: kernel-team-bounces@lists.ubuntu.com BugLink: http://bugs.launchpad.net/bugs/601057 Stanse found that there are two NULL checks missing in ips_monitor. So check their value too and bail out appropriately if the allocation failed. While at it, add one more kfree to the fail path. It is not necessary now, but may be needed in the future when a new allocation is added. And for completeness. Also remove unneeded initialization of the variables. They are all set right after their declaration. Signed-off-by: Jiri Slaby Signed-off-by: Matthew Garrett Acked-by: Jesse Barnes (cherry picked from commit e9ec7f3539cbeae8ffc5d7b30543e5612df5cba3) Signed-off-by: Leann Ogasawara --- drivers/platform/x86/intel_ips.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/intel_ips.c b/drivers/platform/x86/intel_ips.c index cdaf40e..0344822 100644 --- a/drivers/platform/x86/intel_ips.c +++ b/drivers/platform/x86/intel_ips.c @@ -920,9 +920,8 @@ static int ips_monitor(void *data) struct timer_list timer; unsigned long seqno_timestamp, expire, last_msecs, last_sample_period; int i; - u32 *cpu_samples = NULL, *mchp_samples = NULL, old_cpu_power; - u16 *mcp_samples = NULL, *ctv1_samples = NULL, *ctv2_samples = NULL, - *mch_samples = NULL; + u32 *cpu_samples, *mchp_samples, old_cpu_power; + u16 *mcp_samples, *ctv1_samples, *ctv2_samples, *mch_samples; u8 cur_seqno, last_seqno; mcp_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); @@ -931,7 +930,8 @@ static int ips_monitor(void *data) mch_samples = kzalloc(sizeof(u16) * IPS_SAMPLE_COUNT, GFP_KERNEL); cpu_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); mchp_samples = kzalloc(sizeof(u32) * IPS_SAMPLE_COUNT, GFP_KERNEL); - if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples) { + if (!mcp_samples || !ctv1_samples || !ctv2_samples || !mch_samples || + !cpu_samples || !mchp_samples) { dev_err(&ips->dev->dev, "failed to allocate sample array, ips disabled\n"); kfree(mcp_samples); @@ -939,6 +939,7 @@ static int ips_monitor(void *data) kfree(ctv2_samples); kfree(mch_samples); kfree(cpu_samples); + kfree(mchp_samples); kthread_stop(ips->adjust); return -ENOMEM; }