public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code
@ 2011-08-10  8:14 Julia Lawall
  2011-08-12 21:32 ` Jiandong Zheng
  2011-08-19 12:08 ` Artem Bityutskiy
  0 siblings, 2 replies; 3+ messages in thread
From: Julia Lawall @ 2011-08-10  8:14 UTC (permalink / raw)
  To: Jiandong Zheng
  Cc: kernel-janitors, Scott Branden, David Woodhouse, linux-mtd,
	linux-kernel

From: Julia Lawall <julia@diku.dk>

Convert error handling code to use gotos.  At the same time, this adds
calls to kfree and iounmap in a few cases where they were overlooked.

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 drivers/mtd/nand/bcm_umi_nand.c |   33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index a8ae898..46b58d6 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -374,16 +374,18 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 
 	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
-	if (!r)
-		return -ENXIO;
+	if (!r) {
+		err = -ENXIO;
+		goto out_free;
+	}
 
 	/* map physical address */
 	bcm_umi_io_base = ioremap(r->start, resource_size(r));
 
 	if (!bcm_umi_io_base) {
 		printk(KERN_ERR "ioremap to access BCM UMI NAND chip failed\n");
-		kfree(board_mtd);
-		return -EIO;
+		err = -EIO;
+		goto out_free;
 	}
 
 	/* Get pointer to private data */
@@ -399,9 +401,8 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 	/* Initialize the NAND hardware.  */
 	if (bcm_umi_nand_inithw() < 0) {
 		printk(KERN_ERR "BCM UMI NAND chip could not be initialized\n");
-		iounmap(bcm_umi_io_base);
-		kfree(board_mtd);
-		return -EIO;
+		err = -EIO;
+		goto out_unmap;
 	}
 
 	/* Set address of NAND IO lines */
@@ -434,7 +435,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 #if USE_DMA
 	err = nand_dma_init();
 	if (err != 0)
-		return err;
+		goto out_unmap;
 #endif
 
 	/* Figure out the size of the device that we have.
@@ -445,9 +446,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 	err = nand_scan_ident(board_mtd, 1, NULL);
 	if (err) {
 		printk(KERN_ERR "nand_scan failed: %d\n", err);
-		iounmap(bcm_umi_io_base);
-		kfree(board_mtd);
-		return err;
+		goto out_unmap;
 	}
 
 	/* Now that we know the nand size, we can setup the ECC layout */
@@ -466,7 +465,8 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 		{
 			printk(KERN_ERR "NAND - Unrecognized pagesize: %d\n",
 					 board_mtd->writesize);
-			return -EINVAL;
+			err = -EINVAL;
+			goto out_unmap;
 		}
 	}
 
@@ -483,9 +483,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 	err = nand_scan_tail(board_mtd);
 	if (err) {
 		printk(KERN_ERR "nand_scan failed: %d\n", err);
-		iounmap(bcm_umi_io_base);
-		kfree(board_mtd);
-		return err;
+		goto out_unmap;
 	}
 
 	/* Register the partitions */
@@ -494,6 +492,11 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
 
 	/* Return happy */
 	return 0;
+out_unmap:
+	iounmap(bcm_umi_io_base);
+out_free:
+	kfree(board_mtd);
+	return err;
 }
 
 static int bcm_umi_nand_remove(struct platform_device *pdev)


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code
  2011-08-10  8:14 [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code Julia Lawall
@ 2011-08-12 21:32 ` Jiandong Zheng
  2011-08-19 12:08 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Jiandong Zheng @ 2011-08-12 21:32 UTC (permalink / raw)
  To: Julia Lawall
  Cc: kernel-janitors@vger.kernel.org, Scott Branden, David Woodhouse,
	linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org

On 8/10/2011 1:14 AM, Julia Lawall wrote:
> From: Julia Lawall<julia@diku.dk>
>
> Convert error handling code to use gotos.  At the same time, this adds
> calls to kfree and iounmap in a few cases where they were overlooked.
>
> Signed-off-by: Julia Lawall<julia@diku.dk>
>
> ---
>   drivers/mtd/nand/bcm_umi_nand.c |   33 ++++++++++++++++++---------------
>   1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
> index a8ae898..46b58d6 100644
> --- a/drivers/mtd/nand/bcm_umi_nand.c
> +++ b/drivers/mtd/nand/bcm_umi_nand.c
> @@ -374,16 +374,18 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>
>   	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>
> -	if (!r)
> -		return -ENXIO;
> +	if (!r) {
> +		err = -ENXIO;
> +		goto out_free;
> +	}
>
>   	/* map physical address */
>   	bcm_umi_io_base = ioremap(r->start, resource_size(r));
>
>   	if (!bcm_umi_io_base) {
>   		printk(KERN_ERR "ioremap to access BCM UMI NAND chip failed\n");
> -		kfree(board_mtd);
> -		return -EIO;
> +		err = -EIO;
> +		goto out_free;
>   	}
>
>   	/* Get pointer to private data */
> @@ -399,9 +401,8 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>   	/* Initialize the NAND hardware.  */
>   	if (bcm_umi_nand_inithw()<  0) {
>   		printk(KERN_ERR "BCM UMI NAND chip could not be initialized\n");
> -		iounmap(bcm_umi_io_base);
> -		kfree(board_mtd);
> -		return -EIO;
> +		err = -EIO;
> +		goto out_unmap;
>   	}
>
>   	/* Set address of NAND IO lines */
> @@ -434,7 +435,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>   #if USE_DMA
>   	err = nand_dma_init();
>   	if (err != 0)
> -		return err;
> +		goto out_unmap;
>   #endif
>
>   	/* Figure out the size of the device that we have.
> @@ -445,9 +446,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>   	err = nand_scan_ident(board_mtd, 1, NULL);
>   	if (err) {
>   		printk(KERN_ERR "nand_scan failed: %d\n", err);
> -		iounmap(bcm_umi_io_base);
> -		kfree(board_mtd);
> -		return err;
> +		goto out_unmap;
>   	}
>
>   	/* Now that we know the nand size, we can setup the ECC layout */
> @@ -466,7 +465,8 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>   		{
>   			printk(KERN_ERR "NAND - Unrecognized pagesize: %d\n",
>   					 board_mtd->writesize);
> -			return -EINVAL;
> +			err = -EINVAL;
> +			goto out_unmap;
>   		}
>   	}
>
> @@ -483,9 +483,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>   	err = nand_scan_tail(board_mtd);
>   	if (err) {
>   		printk(KERN_ERR "nand_scan failed: %d\n", err);
> -		iounmap(bcm_umi_io_base);
> -		kfree(board_mtd);
> -		return err;
> +		goto out_unmap;
>   	}
>
>   	/* Register the partitions */
> @@ -494,6 +492,11 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
>
>   	/* Return happy */
>   	return 0;
> +out_unmap:
> +	iounmap(bcm_umi_io_base);
> +out_free:
> +	kfree(board_mtd);
> +	return err;
>   }
>
>   static int bcm_umi_nand_remove(struct platform_device *pdev)
>
>
Acked-by: Jiandong Zheng <jdzheng@broadcom.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code
  2011-08-10  8:14 [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code Julia Lawall
  2011-08-12 21:32 ` Jiandong Zheng
@ 2011-08-19 12:08 ` Artem Bityutskiy
  1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2011-08-19 12:08 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Jiandong Zheng, David Woodhouse, linux-mtd, kernel-janitors,
	linux-kernel, Scott Branden

On Wed, 2011-08-10 at 10:14 +0200, Julia Lawall wrote:
> From: Julia Lawall <julia@diku.dk>
> 
> Convert error handling code to use gotos.  At the same time, this adds
> calls to kfree and iounmap in a few cases where they were overlooked.
> 
> Signed-off-by: Julia Lawall <julia@diku.dk> 

Pushed to l2-mtd-2.6.git, thanks!

-- 
Best Regards,
Artem Bityutskiy


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-19 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-10  8:14 [PATCH v3] drivers/mtd/nand/bcm_umi_nand.c: clean up error handling code Julia Lawall
2011-08-12 21:32 ` Jiandong Zheng
2011-08-19 12:08 ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox