From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755932Ab0HXUUt (ORCPT ); Tue, 24 Aug 2010 16:20:49 -0400 Received: from mgw2.diku.dk ([130.225.96.92]:39974 "EHLO mgw2.diku.dk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755390Ab0HXUUr (ORCPT ); Tue, 24 Aug 2010 16:20:47 -0400 Date: Tue, 24 Aug 2010 22:20:45 +0200 (CEST) From: Julia Lawall To: Dan Carpenter Cc: David Airlie , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH 4/5] drivers/char/agp: Eliminate memory leak In-Reply-To: <20100824171644.GL29330@bicker> Message-ID: References: <20100824171644.GL29330@bicker> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Julia Lawall alloc_pci_dev allocates some memory, so that memory should be freed before leaving the function in an error case. A simplified version of the semantic match that finds this problem is: (http://coccinelle.lip6.fr/) // @r exists@ local idexpression x; expression E; identifier f1; iterator I; @@ x = alloc_pci_dev(...); <... when != x when != true (x == NULL || ...) when != if (...) { <+...x...+> } when != I (...) { <+...x...+> } ( x == NULL | x == E | x->f1 ) ...> * return ...; // Signed-off-by: Julia Lawall --- drivers/char/agp/parisc-agp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/agp/parisc-agp.c b/drivers/char/agp/parisc-agp.c index 1c12921..17e380f 100644 --- a/drivers/char/agp/parisc-agp.c +++ b/drivers/char/agp/parisc-agp.c @@ -358,8 +358,12 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa) bridge->dev = fake_bridge_dev; error = agp_add_bridge(bridge); + if (error) + goto fail; + return 0; fail: + kfree(fake_bridge_dev); return error; } From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julia Lawall Date: Tue, 24 Aug 2010 20:20:45 +0000 Subject: Re: [PATCH 4/5] drivers/char/agp: Eliminate memory leak Message-Id: List-Id: References: <20100824171644.GL29330@bicker> In-Reply-To: <20100824171644.GL29330@bicker> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Dan Carpenter Cc: David Airlie , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org From: Julia Lawall alloc_pci_dev allocates some memory, so that memory should be freed before leaving the function in an error case. A simplified version of the semantic match that finds this problem is: (http://coccinelle.lip6.fr/) // @r exists@ local idexpression x; expression E; identifier f1; iterator I; @@ x = alloc_pci_dev(...); <... when != x when != true (x = NULL || ...) when != if (...) { <+...x...+> } when != I (...) { <+...x...+> } ( x = NULL | x = E | x->f1 ) ...> * return ...; // Signed-off-by: Julia Lawall --- drivers/char/agp/parisc-agp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/agp/parisc-agp.c b/drivers/char/agp/parisc-agp.c index 1c12921..17e380f 100644 --- a/drivers/char/agp/parisc-agp.c +++ b/drivers/char/agp/parisc-agp.c @@ -358,8 +358,12 @@ parisc_agp_setup(void __iomem *ioc_hpa, void __iomem *lba_hpa) bridge->dev = fake_bridge_dev; error = agp_add_bridge(bridge); + if (error) + goto fail; + return 0; fail: + kfree(fake_bridge_dev); return error; }