All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia@diku.dk>
To: Paul Mundt <lethal@linux-sh.org>
Cc: kernel-janitors@vger.kernel.org,
	Mike Frysinger <vapier@gentoo.org>,
	Michael Hennerich <michael.hennerich@analog.com>,
	Bryan Wu <cooloney@kernel.org>,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] drivers/video/bf537-lq035.c: Add missing IS_ERR test
Date: Mon, 24 Jan 2011 20:55:21 +0100	[thread overview]
Message-ID: <1295898922-18822-4-git-send-email-julia@diku.dk> (raw)
In-Reply-To: <1295898922-18822-1-git-send-email-julia@diku.dk>

lcd_device_register may return ERR_PTR, so a check is added for this value
before the dereference.  All of the other changes reorganize the error
handling code in this function to avoid duplicating all of it in the added
case.

In the original code, in one case, the global variable fb_buffer was set to
NULL in error code that appears after this variable is initialized.  This
is done now in all error handling code that has this property.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier f;
@@
f(...) { ... return ERR_PTR(...); }

@@
identifier r.f, fld;
expression x;
statement S1,S2;
@@
 x = f(...)
 ... when != IS_ERR(x)
(
 if (IS_ERR(x) ||...) S1 else S2
|
*x->fld
)
// </smpl>

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

---
 drivers/video/bf537-lq035.c |   58 +++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/drivers/video/bf537-lq035.c b/drivers/video/bf537-lq035.c
index 18c5078..47c21fb 100644
--- a/drivers/video/bf537-lq035.c
+++ b/drivers/video/bf537-lq035.c
@@ -696,6 +696,7 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 {
 	struct backlight_properties props;
 	dma_addr_t dma_handle;
+	int ret;
 
 	if (request_dma(CH_PPI, KBUILD_MODNAME)) {
 		pr_err("couldn't request PPI DMA\n");
@@ -704,17 +705,16 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	if (request_ports()) {
 		pr_err("couldn't request gpio port\n");
-		free_dma(CH_PPI);
-		return -EFAULT;
+		ret = -EFAULT;
+		goto out_ports;
 	}
 
 	fb_buffer = dma_alloc_coherent(NULL, TOTAL_VIDEO_MEM_SIZE,
 				       &dma_handle, GFP_KERNEL);
 	if (fb_buffer == NULL) {
 		pr_err("couldn't allocate dma buffer\n");
-		free_dma(CH_PPI);
-		free_ports();
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_dma_coherent;
 	}
 
 	if (L1_DATA_A_LENGTH)
@@ -725,10 +725,8 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	if (dma_desc_table == NULL) {
 		pr_err("couldn't allocate dma descriptor\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_table;
 	}
 
 	bfin_lq035_fb.screen_base = (void *)fb_buffer;
@@ -771,31 +769,21 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 	bfin_lq035_fb.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
 	if (bfin_lq035_fb.pseudo_palette == NULL) {
 		pr_err("failed to allocate pseudo_palette\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_palette;
 	}
 
 	if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) {
 		pr_err("failed to allocate colormap (%d entries)\n",
 			NBR_PALETTE);
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		kfree(bfin_lq035_fb.pseudo_palette);
-		return -EFAULT;
+		ret = -EFAULT;
+		goto out_cmap;
 	}
 
 	if (register_framebuffer(&bfin_lq035_fb) < 0) {
 		pr_err("unable to register framebuffer\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		fb_buffer = NULL;
-		kfree(bfin_lq035_fb.pseudo_palette);
-		fb_dealloc_cmap(&bfin_lq035_fb.cmap);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_reg;
 	}
 
 	i2c_add_driver(&ad5280_driver);
@@ -807,11 +795,31 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	lcd_dev = lcd_device_register(KBUILD_MODNAME, &pdev->dev, NULL,
 				      &bfin_lcd_ops);
+	if (IS_ERR(lcd_dev)) {
+		pr_err("unable to register lcd\n");
+		ret = PTR_ERR(lcd_dev);
+		goto out_lcd;
+	}
 	lcd_dev->props.max_contrast = 255,
 
 	pr_info("initialized");
 
 	return 0;
+out_lcd:
+	unregister_framebuffer(&bfin_lq035_fb);
+out_reg:
+	fb_dealloc_cmap(&bfin_lq035_fb.cmap);
+out_cmap:
+	kfree(bfin_lq035_fb.pseudo_palette);
+out_palette:
+out_table:
+	dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
+	fb_buffer = NULL;
+out_dma_coherent:
+	free_ports();
+out_ports:
+	free_dma(CH_PPI);
+	return ret;
 }
 
 static int __devexit bfin_lq035_remove(struct platform_device *pdev)


WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia@diku.dk>
To: Paul Mundt <lethal@linux-sh.org>
Cc: kernel-janitors@vger.kernel.org,
	Mike Frysinger <vapier@gentoo.org>,
	Michael Hennerich <michael.hennerich@analog.com>,
	Bryan Wu <cooloney@kernel.org>,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] drivers/video/bf537-lq035.c: Add missing IS_ERR test
Date: Mon, 24 Jan 2011 19:55:21 +0000	[thread overview]
Message-ID: <1295898922-18822-4-git-send-email-julia@diku.dk> (raw)
In-Reply-To: <1295898922-18822-1-git-send-email-julia@diku.dk>

lcd_device_register may return ERR_PTR, so a check is added for this value
before the dereference.  All of the other changes reorganize the error
handling code in this function to avoid duplicating all of it in the added
case.

In the original code, in one case, the global variable fb_buffer was set to
NULL in error code that appears after this variable is initialized.  This
is done now in all error handling code that has this property.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
identifier f;
@@
f(...) { ... return ERR_PTR(...); }

@@
identifier r.f, fld;
expression x;
statement S1,S2;
@@
 x = f(...)
 ... when != IS_ERR(x)
(
 if (IS_ERR(x) ||...) S1 else S2
|
*x->fld
)
// </smpl>

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

---
 drivers/video/bf537-lq035.c |   58 +++++++++++++++++++++++++-------------------
 1 file changed, 33 insertions(+), 25 deletions(-)

diff --git a/drivers/video/bf537-lq035.c b/drivers/video/bf537-lq035.c
index 18c5078..47c21fb 100644
--- a/drivers/video/bf537-lq035.c
+++ b/drivers/video/bf537-lq035.c
@@ -696,6 +696,7 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 {
 	struct backlight_properties props;
 	dma_addr_t dma_handle;
+	int ret;
 
 	if (request_dma(CH_PPI, KBUILD_MODNAME)) {
 		pr_err("couldn't request PPI DMA\n");
@@ -704,17 +705,16 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	if (request_ports()) {
 		pr_err("couldn't request gpio port\n");
-		free_dma(CH_PPI);
-		return -EFAULT;
+		ret = -EFAULT;
+		goto out_ports;
 	}
 
 	fb_buffer = dma_alloc_coherent(NULL, TOTAL_VIDEO_MEM_SIZE,
 				       &dma_handle, GFP_KERNEL);
 	if (fb_buffer = NULL) {
 		pr_err("couldn't allocate dma buffer\n");
-		free_dma(CH_PPI);
-		free_ports();
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_dma_coherent;
 	}
 
 	if (L1_DATA_A_LENGTH)
@@ -725,10 +725,8 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	if (dma_desc_table = NULL) {
 		pr_err("couldn't allocate dma descriptor\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_table;
 	}
 
 	bfin_lq035_fb.screen_base = (void *)fb_buffer;
@@ -771,31 +769,21 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 	bfin_lq035_fb.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
 	if (bfin_lq035_fb.pseudo_palette = NULL) {
 		pr_err("failed to allocate pseudo_palette\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		return -ENOMEM;
+		ret = -ENOMEM;
+		goto out_palette;
 	}
 
 	if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) {
 		pr_err("failed to allocate colormap (%d entries)\n",
 			NBR_PALETTE);
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		kfree(bfin_lq035_fb.pseudo_palette);
-		return -EFAULT;
+		ret = -EFAULT;
+		goto out_cmap;
 	}
 
 	if (register_framebuffer(&bfin_lq035_fb) < 0) {
 		pr_err("unable to register framebuffer\n");
-		free_dma(CH_PPI);
-		free_ports();
-		dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
-		fb_buffer = NULL;
-		kfree(bfin_lq035_fb.pseudo_palette);
-		fb_dealloc_cmap(&bfin_lq035_fb.cmap);
-		return -EINVAL;
+		ret = -EINVAL;
+		goto out_reg;
 	}
 
 	i2c_add_driver(&ad5280_driver);
@@ -807,11 +795,31 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
 
 	lcd_dev = lcd_device_register(KBUILD_MODNAME, &pdev->dev, NULL,
 				      &bfin_lcd_ops);
+	if (IS_ERR(lcd_dev)) {
+		pr_err("unable to register lcd\n");
+		ret = PTR_ERR(lcd_dev);
+		goto out_lcd;
+	}
 	lcd_dev->props.max_contrast = 255,
 
 	pr_info("initialized");
 
 	return 0;
+out_lcd:
+	unregister_framebuffer(&bfin_lq035_fb);
+out_reg:
+	fb_dealloc_cmap(&bfin_lq035_fb.cmap);
+out_cmap:
+	kfree(bfin_lq035_fb.pseudo_palette);
+out_palette:
+out_table:
+	dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
+	fb_buffer = NULL;
+out_dma_coherent:
+	free_ports();
+out_ports:
+	free_dma(CH_PPI);
+	return ret;
 }
 
 static int __devexit bfin_lq035_remove(struct platform_device *pdev)


  parent reply	other threads:[~2011-01-24 19:36 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-24 19:55 [PATCH 0/4] Add missing IS_ERR test Julia Lawall
2011-01-24 19:55 ` Julia Lawall
2011-01-24 19:55 ` [PATCH 1/4] fs/btrfs/inode.c: " Julia Lawall
2011-01-24 19:55   ` Julia Lawall
2011-01-24 19:55 ` [PATCH 2/4] arch/arm/mach-at91/clock.c: " Julia Lawall
2011-01-24 19:55   ` Julia Lawall
2011-01-24 19:55   ` Julia Lawall
2011-01-24 19:56   ` Ryan Mallon
2011-01-24 19:56     ` Ryan Mallon
2011-01-24 19:56     ` Ryan Mallon
2011-01-24 20:00     ` Julia Lawall
2011-01-24 20:00       ` Julia Lawall
2011-01-24 20:00       ` Julia Lawall
2011-01-24 20:05       ` Vasiliy Kulikov
2011-01-24 20:05         ` Vasiliy Kulikov
2011-01-24 20:05         ` Vasiliy Kulikov
2011-01-24 20:09         ` Julia Lawall
2011-01-24 20:09           ` Julia Lawall
2011-01-24 20:09           ` Julia Lawall
2011-01-24 20:14           ` Vasiliy Kulikov
2011-01-24 20:14             ` Vasiliy Kulikov
2011-01-24 20:14             ` Vasiliy Kulikov
2011-01-25 10:33           ` walter harms
2011-01-25 10:33             ` walter harms
2011-01-25 10:33             ` walter harms
2011-01-25 10:43             ` Russell King - ARM Linux
2011-01-25 10:43               ` Russell King - ARM Linux
2011-01-25 10:43               ` Russell King - ARM Linux
2011-01-25 11:12               ` walter harms
2011-01-25 11:12                 ` walter harms
2011-01-25 11:12                 ` walter harms
2011-01-25 11:17                 ` Russell King - ARM Linux
2011-01-25 11:17                   ` Russell King - ARM Linux
2011-01-25 11:17                   ` Russell King - ARM Linux
2011-01-25 11:18                 ` Julia Lawall
2011-01-25 11:18                   ` Julia Lawall
2011-01-25 11:18                   ` Julia Lawall
2011-01-25 11:26                   ` Russell King - ARM Linux
2011-01-25 11:26                     ` Russell King - ARM Linux
2011-01-25 11:26                     ` Russell King - ARM Linux
2011-01-25 11:31                     ` Julia Lawall
2011-01-25 11:31                       ` Julia Lawall
2011-01-25 11:31                       ` Julia Lawall
2011-01-24 20:11         ` Ryan Mallon
2011-01-24 20:11           ` Ryan Mallon
2011-01-24 20:11           ` Ryan Mallon
2011-01-24 20:28           ` Julia Lawall
2011-01-24 20:28             ` Julia Lawall
2011-01-24 20:28             ` Julia Lawall
2011-01-24 20:38             ` Ryan Mallon
2011-01-24 20:38               ` Ryan Mallon
2011-01-24 20:38               ` Ryan Mallon
2011-01-24 21:01               ` Julia Lawall
2011-01-24 21:01                 ` Julia Lawall
2011-01-24 21:01                 ` Julia Lawall
2011-01-24 21:06                 ` Ryan Mallon
2011-01-24 21:06                   ` Ryan Mallon
2011-01-24 21:06                   ` Ryan Mallon
2011-01-24 21:31                   ` Julia Lawall
2011-01-24 21:31                     ` Julia Lawall
2011-01-24 21:31                     ` Julia Lawall
2011-01-24 21:51                     ` Ryan Mallon
2011-01-24 21:51                       ` Ryan Mallon
2011-01-24 21:51                       ` Ryan Mallon
2011-01-24 23:23                       ` Russell King - ARM Linux
2011-01-24 23:23                         ` Russell King - ARM Linux
2011-01-24 23:23                         ` Russell King - ARM Linux
2011-01-25  1:44                         ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-25  1:44                           ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-25  1:44                           ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-25  6:12                           ` Julia Lawall
2011-01-25  6:12                             ` Julia Lawall
2011-01-25  6:12                             ` Julia Lawall
2011-01-25 17:23                             ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-25 17:23                               ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-25 17:23                               ` Jean-Christophe PLAGNIOL-VILLARD
2011-01-24 19:55 ` Julia Lawall [this message]
2011-01-24 19:55   ` [PATCH 3/4] drivers/video/bf537-lq035.c: " Julia Lawall
2011-01-24 20:43   ` Mike Frysinger
2011-01-24 20:43     ` Mike Frysinger
2011-01-25  6:12     ` Paul Mundt
2011-01-25  6:12       ` Paul Mundt
2011-01-25  8:36   ` Hennerich, Michael
2011-01-25  8:36     ` Hennerich, Michael
2011-01-24 19:55 ` [PATCH 4/4] arch/arm/mach-omap2/smartreflex.c: " Julia Lawall
2011-01-24 19:55   ` Julia Lawall
2011-01-24 19:55   ` Julia Lawall
2011-01-24 21:24   ` Kevin Hilman
2011-01-24 21:24     ` Kevin Hilman
2011-01-24 21:24     ` Kevin Hilman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1295898922-18822-4-git-send-email-julia@diku.dk \
    --to=julia@diku.dk \
    --cc=cooloney@kernel.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=lethal@linux-sh.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --cc=vapier@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.