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: 1399691 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 264533FC71 for ; Mon, 3 Sep 2012 12:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756040Ab2ICMm3 (ORCPT ); Mon, 3 Sep 2012 08:42:29 -0400 Received: from mail-qc0-f174.google.com ([209.85.216.174]:61577 "EHLO mail-qc0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751656Ab2ICMm2 (ORCPT ); Mon, 3 Sep 2012 08:42:28 -0400 Received: by qcro28 with SMTP id o28so3318783qcr.19 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 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 Acked-by: Kevin Hilman --- arch/arm/mach-omap2/gpio.c | 2 ++ 1 file changed, 2 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..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; }