From patchwork Mon Sep 3 10:13:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 1399321 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 162523FC33 for ; Mon, 3 Sep 2012 10:13:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756243Ab2ICKNf (ORCPT ); Mon, 3 Sep 2012 06:13:35 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:53398 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756236Ab2ICKNe (ORCPT ); Mon, 3 Sep 2012 06:13:34 -0400 Received: by qcro28 with SMTP id o28so3263583qcr.19 for ; Mon, 03 Sep 2012 03:13:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=kKDapjEgd8kZKVzjIPAI2WHPMkXzmRQUEP0PUMh7A9E=; b=KE3M46M79ZWTLcv3RC7VlMca5GWk8YOs5wlbfsI0HMwwRE50CEcsxTjGJgB5aRZMns cy/tnpN/ITpsBWwCKl2aVAlk+6Oocz8qC7N7vG1xW8AZ0IUU1wl/tr2MNDkNaf/Vtlxx /+PDHaXqvJded5zY6q5TxtLuIH1McUxEd1zETJ3+YApZakge4TSfJobKwhXqmuHskVy3 qPjZyH9KaGq8Sbqz/0PdT+i2aeIS5j7EkwzX2YsOtEC2FhYIlWWlTt8+RtWaGdKCiuJ0 7kYrGnSGBm0N0uU5kBLSc0DEEWY77jYIxfTKJnZ3KR7hDqXx/1m/vmtJRms+wjEkiFjA eR2w== MIME-Version: 1.0 Received: by 10.224.193.132 with SMTP id du4mr33442644qab.75.1346667213895; Mon, 03 Sep 2012 03:13:33 -0700 (PDT) Received: by 10.229.146.194 with HTTP; Mon, 3 Sep 2012 03:13:33 -0700 (PDT) Date: Mon, 3 Sep 2012 18:13:33 +0800 Message-ID: Subject: [PATCH] gpio/omap: fix possible memory leak in omap2_gpio_dev_init() From: Wei Yongjun To: tony@atomide.com, linux@arm.linux.org.uk Cc: yongjun_wei@trendmicro.com.cn, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Wei Yongjun pdata and pdata->regs have been allocated in this function and should be freed before leaving it, and in the other error handling cases too. spatch with a semantic match is used to found this problem. (http://coccinelle.lip6.fr/) Signed-off-by: Wei Yongjun --- arch/arm/mach-omap2/gpio.c | 3 +++ 1 file changed, 3 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/mach-omap2/gpio.c b/arch/arm/mach-omap2/gpio.c index 9ad7d48..3bfa4bb 100644 --- a/arch/arm/mach-omap2/gpio.c +++ b/arch/arm/mach-omap2/gpio.c @@ -60,6 +60,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) pdata->regs = kzalloc(sizeof(struct omap_gpio_reg_offs), GFP_KERNEL); if (!pdata->regs) { pr_err("gpio%d: Memory allocation failed\n", id); + kfree(pdata); return -ENOMEM; } @@ -121,6 +122,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) break; default: WARN(1, "Invalid gpio bank_type\n"); + kfree(pdata->regs); kfree(pdata); return -EINVAL; } @@ -130,6 +132,7 @@ static int __init omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused) pdev = omap_device_build(name, id - 1, oh, pdata, sizeof(*pdata), NULL, 0, false); + kfree(pdata->regs); kfree(pdata); if (IS_ERR(pdev)) {