From patchwork Fri Jul 9 15:04:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nishanth Menon X-Patchwork-Id: 111066 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o69F38DD004271 for ; Fri, 9 Jul 2010 15:05:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756993Ab0GIPEn (ORCPT ); Fri, 9 Jul 2010 11:04:43 -0400 Received: from bear.ext.ti.com ([192.94.94.41]:54326 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754816Ab0GIPEn (ORCPT ); Fri, 9 Jul 2010 11:04:43 -0400 Received: from dlep34.itg.ti.com ([157.170.170.115]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id o69F4dPR017097 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 9 Jul 2010 10:04:39 -0500 Received: from legion.dal.design.ti.com (localhost [127.0.0.1]) by dlep34.itg.ti.com (8.13.7/8.13.7) with ESMTP id o69F4aqK016277; Fri, 9 Jul 2010 10:04:36 -0500 (CDT) Received: from senorita (senorita.am.dhcp.ti.com [128.247.74.250]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id o69F4aP11983; Fri, 9 Jul 2010 10:04:36 -0500 (CDT) Received: by senorita (Postfix, from userid 1000) id 3830FC258; Fri, 9 Jul 2010 10:04:36 -0500 (CDT) From: Nishanth Menon To: linux-omap Cc: Artem Bityutskiy , Kevin Hilman , Thara Gopinath , Peter p2 De Schrijver , Nishanth Menon Subject: [PM-SR][PATCH 1/2 v2] omap3: sr: fix memory leak and simplify the code Date: Fri, 9 Jul 2010 10:04:34 -0500 Message-Id: <1278687874-26123-1-git-send-email-nm@ti.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <[PATCH 1/2] omap3: sr: fix memory leak and simplify the code> References: <[PATCH 1/2] omap3: sr: fix memory leak and simplify the code> Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 09 Jul 2010 15:05:31 +0000 (UTC) From: Artem Bityutskiy This patch fixes the following problem indicated by kmemleak: kmemleak: unreferenced object 0xdf93c280 (size 64): kmemleak: backtrace: kmemleak: [] create_object+0x104/0x200 kmemleak: [] kmem_cache_alloc+0xe4/0xf4 kmemleak: [] omap_devinit_smartreflex+0x44/0x244 kmemleak: [] do_one_initcall+0x5c/0x1b8 kmemleak: [] kernel_init+0x94/0x110 kmemleak: [] kernel_thread_exit+0x0/0x8 The reason is that 'omap_devinit_smartreflex()' allocates 'sr_data', then passes it to 'omap_device_build()', which 'kmemdup()'s it and uses the copy. But 'omap_devinit_smartreflex()' never frees 'sr_data'. This patch make 'sr_data' to be a stack variable, which eliminates the memory leak and simplifies the code a bit. Cc: Kevin Hilman Cc: Thara Gopinath , Cc: Peter p2 De Schrijver Cc: Nishanth Menon Signed-off-by: Artem Bityutskiy Acked-by: Nishanth Menon --- Changes from V1: rebased to latest pm-sr branch default of sr_data set to 0 to make it equivalent to kzalloc NOTE: this probably should be squashed when being send upstream along with rest of SR series arch/arm/mach-omap2/sr_device.c | 27 +++++++++------------------ 1 files changed, 9 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-omap2/sr_device.c b/arch/arm/mach-omap2/sr_device.c index dbf7603..ecc9910 100644 --- a/arch/arm/mach-omap2/sr_device.c +++ b/arch/arm/mach-omap2/sr_device.c @@ -116,19 +116,12 @@ static void __init sr_set_nvalues(struct omap_sr_dev_data *dev_data, static int sr_dev_init(struct omap_hwmod *oh, void *user) { - struct omap_sr_data *sr_data; + struct omap_sr_data sr_data = {0}; struct omap_sr_dev_data *sr_dev_data; struct omap_device *od; char *name = "smartreflex"; static int i; - sr_data = kzalloc(sizeof(struct omap_sr_data), GFP_KERNEL); - if (!sr_data) { - pr_err("%s: Unable to allocate memory for %s sr_data.Error!\n", - __func__, oh->name); - return -ENOMEM; - } - sr_dev_data = (struct omap_sr_dev_data *)oh->dev_attr; /* * OMAP3430 ES3.1 chips by default come with Efuse burnt @@ -139,32 +132,30 @@ static int sr_dev_init(struct omap_hwmod *oh, void *user) */ if (cpu_is_omap343x()) { if (omap_rev() == OMAP3430_REV_ES3_1) - sr_data->enable_on_init = true; + sr_data.enable_on_init = true; else - sr_data->enable_on_init = false; + sr_data.enable_on_init = false; } else { - sr_data->enable_on_init = false; + sr_data.enable_on_init = false; } - sr_data->device_enable = omap_device_enable; - sr_data->device_shutdown = omap_device_shutdown; - sr_data->device_idle = omap_device_idle; + sr_data.device_enable = omap_device_enable; + sr_data.device_shutdown = omap_device_shutdown; + sr_data.device_idle = omap_device_idle; sr_dev_data->volts_supported = omap_get_voltage_table(i, &sr_dev_data->volt_data); if (!sr_dev_data->volts_supported) { pr_warning("%s: No Voltage table registerd fo VDD%d.Something \ really wrong\n\n", __func__, i + 1); i++; - kfree(sr_data); return 0; } - sr_set_nvalues(sr_dev_data, sr_data); - od = omap_device_build(name, i, oh, sr_data, sizeof(*sr_data), + sr_set_nvalues(sr_dev_data, &sr_data); + od = omap_device_build(name, i, oh, &sr_data, sizeof(sr_data), omap_sr_latency, ARRAY_SIZE(omap_sr_latency), 0); if (IS_ERR(od)) { pr_warning("%s: Could not build omap_device for %s: %s.\n\n", __func__, name, oh->name); - kfree(sr_data); } i++; return 0;