From patchwork Mon Sep 3 12:42:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 1399701 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id E0B4F3FC71 for ; Mon, 3 Sep 2012 12:45:36 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T8VzC-0004nk-7Q; Mon, 03 Sep 2012 12:42:38 +0000 Received: from mail-qc0-f177.google.com ([209.85.216.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T8Vz5-0004la-Lk for linux-arm-kernel@lists.infradead.org; Mon, 03 Sep 2012 12:42:36 +0000 Received: by qcsu28 with SMTP id u28so3566430qcs.36 for ; Mon, 03 Sep 2012 05:42:28 -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=t8ziqEtWydpQVvK/0j+nI1YyGkRsdIw474SkCPfenPM=; b=07zamK7pDqw4SbuuSrDwVs5S/gSAszkxhbfwj2Mx9Jo3tKk68hJFv16gRaHQ4JQO1/ /G+cggBtAdt4LgU3xrGgwnOIXgxhmu1etMt9tEfCDwP0djn6nz4DewvmWzMhP9IS+X70 2jCc2xARTuhRqb9FEp3dmRH0VLtECqS3Jft/qtLeQGRU3mwas1uRsvSqc6Q4g2V4rat8 hLDyXp4l0bC1RxluTbbEYzvOGnfQlwDXVDiw46+8knmHVUAdNTO3KpAfEt4/O25nnOLK EyNegBzSZUJIIrQ8xv/X6/zpgKKLVY0QOX1ZWg0bKdxfp4hFCjB15CZzm8MYlXwLouJw Q94A== MIME-Version: 1.0 Received: by 10.224.185.15 with SMTP id cm15mr34464774qab.8.1346676147948; Mon, 03 Sep 2012 05:42:27 -0700 (PDT) Received: by 10.229.146.194 with HTTP; Mon, 3 Sep 2012 05:42:27 -0700 (PDT) Date: Mon, 3 Sep 2012 20:42:27 +0800 Message-ID: Subject: [PATCH v2] gpio/omap: fix possible memory leak in omap2_gpio_dev_init() From: Wei Yongjun To: tony@atomide.com, linux@arm.linux.org.uk, paul@pwsan.com 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.177 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 Acked-by: Kevin Hilman --- arch/arm/mach-omap2/gpio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm/mach-omap2/gpio.c b/arch/arm/mach-omap2/gpio.c index 9ad7d48..fe626e90 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; }