Commit 5dc1365c authored by Julia Lawall's avatar Julia Lawall Committed by Paul Mundt

drivers/video/bf537-lq035.c: Add missing IS_ERR test

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: default avatarJulia Lawall <julia@diku.dk>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
Signed-off-by: default avatarPaul Mundt <lethal@linux-sh.org>
parent e88e43b0
...@@ -696,6 +696,7 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev) ...@@ -696,6 +696,7 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
{ {
struct backlight_properties props; struct backlight_properties props;
dma_addr_t dma_handle; dma_addr_t dma_handle;
int ret;
if (request_dma(CH_PPI, KBUILD_MODNAME)) { if (request_dma(CH_PPI, KBUILD_MODNAME)) {
pr_err("couldn't request PPI DMA\n"); pr_err("couldn't request PPI DMA\n");
...@@ -704,17 +705,16 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev) ...@@ -704,17 +705,16 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
if (request_ports()) { if (request_ports()) {
pr_err("couldn't request gpio port\n"); pr_err("couldn't request gpio port\n");
free_dma(CH_PPI); ret = -EFAULT;
return -EFAULT; goto out_ports;
} }
fb_buffer = dma_alloc_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer = dma_alloc_coherent(NULL, TOTAL_VIDEO_MEM_SIZE,
&dma_handle, GFP_KERNEL); &dma_handle, GFP_KERNEL);
if (fb_buffer == NULL) { if (fb_buffer == NULL) {
pr_err("couldn't allocate dma buffer\n"); pr_err("couldn't allocate dma buffer\n");
free_dma(CH_PPI); ret = -ENOMEM;
free_ports(); goto out_dma_coherent;
return -ENOMEM;
} }
if (L1_DATA_A_LENGTH) if (L1_DATA_A_LENGTH)
...@@ -725,10 +725,8 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev) ...@@ -725,10 +725,8 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
if (dma_desc_table == NULL) { if (dma_desc_table == NULL) {
pr_err("couldn't allocate dma descriptor\n"); pr_err("couldn't allocate dma descriptor\n");
free_dma(CH_PPI); ret = -ENOMEM;
free_ports(); goto out_table;
dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
return -ENOMEM;
} }
bfin_lq035_fb.screen_base = (void *)fb_buffer; bfin_lq035_fb.screen_base = (void *)fb_buffer;
...@@ -771,31 +769,21 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev) ...@@ -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); bfin_lq035_fb.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL);
if (bfin_lq035_fb.pseudo_palette == NULL) { if (bfin_lq035_fb.pseudo_palette == NULL) {
pr_err("failed to allocate pseudo_palette\n"); pr_err("failed to allocate pseudo_palette\n");
free_dma(CH_PPI); ret = -ENOMEM;
free_ports(); goto out_palette;
dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
return -ENOMEM;
} }
if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) { if (fb_alloc_cmap(&bfin_lq035_fb.cmap, NBR_PALETTE, 0) < 0) {
pr_err("failed to allocate colormap (%d entries)\n", pr_err("failed to allocate colormap (%d entries)\n",
NBR_PALETTE); NBR_PALETTE);
free_dma(CH_PPI); ret = -EFAULT;
free_ports(); goto out_cmap;
dma_free_coherent(NULL, TOTAL_VIDEO_MEM_SIZE, fb_buffer, 0);
kfree(bfin_lq035_fb.pseudo_palette);
return -EFAULT;
} }
if (register_framebuffer(&bfin_lq035_fb) < 0) { if (register_framebuffer(&bfin_lq035_fb) < 0) {
pr_err("unable to register framebuffer\n"); pr_err("unable to register framebuffer\n");
free_dma(CH_PPI); ret = -EINVAL;
free_ports(); goto out_reg;
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;
} }
i2c_add_driver(&ad5280_driver); i2c_add_driver(&ad5280_driver);
...@@ -807,11 +795,31 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev) ...@@ -807,11 +795,31 @@ static int __devinit bfin_lq035_probe(struct platform_device *pdev)
lcd_dev = lcd_device_register(KBUILD_MODNAME, &pdev->dev, NULL, lcd_dev = lcd_device_register(KBUILD_MODNAME, &pdev->dev, NULL,
&bfin_lcd_ops); &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, lcd_dev->props.max_contrast = 255,
pr_info("initialized"); pr_info("initialized");
return 0; 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) static int __devexit bfin_lq035_remove(struct platform_device *pdev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment