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: 1399361 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 0CB13DFFD0 for ; Mon, 3 Sep 2012 10:20:45 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T8Tf4-0004iC-D0; Mon, 03 Sep 2012 10:13:42 +0000 Received: from mail-qa0-f42.google.com ([209.85.216.42]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T8Tez-0004gr-IX for linux-arm-kernel@lists.infradead.org; Mon, 03 Sep 2012 10:13:39 +0000 Received: by qaeb19 with SMTP id b19so2096953qae.15 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 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (weiyj.lk[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.42 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: yongjun_wei@trendmicro.com.cn, linux-omap@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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(+) 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)) {