Patch 1 fixes a possible memory leak in the driver.
Rest 3 patches add/update usage of devm_ apis.
These patches are only build-tested.
Tushar Behera (4):
video: vt8500: Fix memory leak in probe function
video: vt8500: Fix invalid free of devm_ allocated data
video: vt8500: Convert to use devm_request_mem_region()
video: vt8500: Convert to use devm_ioremap()
drivers/video/vt8500lcdfb.c | 47 +++++++++++++++---------------------------
1 files changed, 17 insertions(+), 30 deletions(-)
--
1.7.4.1
On Thu, 2012-11-22 at 12:12 +0530, Tushar Behera wrote:
> Patch 1 fixes a possible memory leak in the driver.
> Rest 3 patches add/update usage of devm_ apis.
>
> These patches are only build-tested.
>
> Tushar Behera (4):
> video: vt8500: Fix memory leak in probe function
> video: vt8500: Fix invalid free of devm_ allocated data
> video: vt8500: Convert to use devm_request_mem_region()
> video: vt8500: Convert to use devm_ioremap()
>
> drivers/video/vt8500lcdfb.c | 47 +++++++++++++++---------------------------
> 1 files changed, 17 insertions(+), 30 deletions(-)
>
Thanks for the tidy up.
All patches Acked-by: Tony Prisk <[email protected]>
While at it, fix the return statements.
Signed-off-by: Tushar Behera <[email protected]>
---
drivers/video/vt8500lcdfb.c | 12 +++---------
1 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c
index 2438368..c42f15d 100644
--- a/drivers/video/vt8500lcdfb.c
+++ b/drivers/video/vt8500lcdfb.c
@@ -330,7 +330,8 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
return -ENODEV;
}
- res = request_mem_region(res->start, resource_size(res), "vt8500lcd");
+ res = devm_request_mem_region(&pdev->dev, res->start,
+ resource_size(res), "vt8500lcd");
if (res == NULL) {
dev_err(&pdev->dev, "failed to request I/O memory\n");
return -EBUSY;
@@ -339,8 +340,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
fbi->regbase = ioremap(res->start, resource_size(res));
if (fbi->regbase == NULL) {
dev_err(&pdev->dev, "failed to map I/O memory\n");
- ret = -EBUSY;
- goto failed_free_res;
+ return -EBUSY;
}
np = of_parse_phandle(pdev->dev.of_node, "default-mode", 0);
@@ -461,15 +461,12 @@ failed_free_fbmem:
fbi->fb.screen_base, fbi->fb.fix.smem_start);
failed_free_io:
iounmap(fbi->regbase);
-failed_free_res:
- release_mem_region(res->start, resource_size(res));
return ret;
}
static int __devexit vt8500lcd_remove(struct platform_device *pdev)
{
struct vt8500lcd_info *fbi = platform_get_drvdata(pdev);
- struct resource *res;
int irq;
unregister_framebuffer(&fbi->fb);
@@ -491,9 +488,6 @@ static int __devexit vt8500lcd_remove(struct platform_device *pdev)
iounmap(fbi->regbase);
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- release_mem_region(res->start, resource_size(res));
-
return 0;
}
--
1.7.4.1
In case of error in probe function, there is a possibility of
either iounmap not getting called or memory allocated for fb_mem_virt
not getting freed.
Signed-off-by: Tushar Behera <[email protected]>
---
drivers/video/vt8500lcdfb.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c
index 9af8da7..5777adc 100644
--- a/drivers/video/vt8500lcdfb.c
+++ b/drivers/video/vt8500lcdfb.c
@@ -350,7 +350,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
if (!np) {
pr_err("%s: No display description in Device Tree\n", __func__);
ret = -EINVAL;
- goto failed_free_res;
+ goto failed_free_io;
}
/*
@@ -369,7 +369,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
ret |= of_property_read_u32(np, "bpp", &bpp);
if (ret) {
pr_err("%s: Unable to read display properties\n", __func__);
- goto failed_free_res;
+ goto failed_free_io;
}
of_mode.vmode = FB_VMODE_NONINTERLACED;
@@ -379,7 +379,8 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!fb_mem_virt) {
pr_err("%s: Failed to allocate framebuffer\n", __func__);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto failed_free_io;
};
fbi->fb.fix.smem_start = fb_mem_phys;
@@ -394,7 +395,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
if (fbi->palette_cpu == NULL) {
dev_err(&pdev->dev, "Failed to allocate palette buffer\n");
ret = -ENOMEM;
- goto failed_free_io;
+ goto failed_free_fbmem;
}
irq = platform_get_irq(pdev, 0);
@@ -458,6 +459,9 @@ failed_free_irq:
failed_free_palette:
dma_free_coherent(&pdev->dev, fbi->palette_size,
fbi->palette_cpu, fbi->palette_phys);
+failed_free_fbmem:
+ dma_free_coherent(&pdev->dev, fbi->fb.fix.smem_len,
+ fbi->fb.screen_base, fbi->fb.fix.smem_start);
failed_free_io:
iounmap(fbi->regbase);
failed_free_res:
@@ -485,6 +489,10 @@ static int __devexit vt8500lcd_remove(struct platform_device *pdev)
irq = platform_get_irq(pdev, 0);
free_irq(irq, fbi);
+ if (fbi->fb.screen_base)
+ dma_free_coherent(&pdev->dev, fbi->fb.fix.smem_len,
+ fbi->fb.screen_base, fbi->fb.fix.smem_start);
+
dma_free_coherent(&pdev->dev, fbi->palette_size,
fbi->palette_cpu, fbi->palette_phys);
--
1.7.4.1
While at it, fix the return statements.
Signed-off-by: Tushar Behera <[email protected]>
---
drivers/video/vt8500lcdfb.c | 14 ++++----------
1 files changed, 4 insertions(+), 10 deletions(-)
diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c
index c42f15d..96a955e 100644
--- a/drivers/video/vt8500lcdfb.c
+++ b/drivers/video/vt8500lcdfb.c
@@ -337,7 +337,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
return -EBUSY;
}
- fbi->regbase = ioremap(res->start, resource_size(res));
+ fbi->regbase = devm_ioremap(&pdev->dev, res->start, resource_size(res));
if (fbi->regbase == NULL) {
dev_err(&pdev->dev, "failed to map I/O memory\n");
return -EBUSY;
@@ -346,8 +346,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
np = of_parse_phandle(pdev->dev.of_node, "default-mode", 0);
if (!np) {
pr_err("%s: No display description in Device Tree\n", __func__);
- ret = -EINVAL;
- goto failed_free_io;
+ return -EINVAL;
}
/*
@@ -366,7 +365,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
ret |= of_property_read_u32(np, "bpp", &bpp);
if (ret) {
pr_err("%s: Unable to read display properties\n", __func__);
- goto failed_free_io;
+ return ret;
}
of_mode.vmode = FB_VMODE_NONINTERLACED;
@@ -376,8 +375,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!fb_mem_virt) {
pr_err("%s: Failed to allocate framebuffer\n", __func__);
- ret = -ENOMEM;
- goto failed_free_io;
+ return -ENOMEM;
};
fbi->fb.fix.smem_start = fb_mem_phys;
@@ -459,8 +457,6 @@ failed_free_palette:
failed_free_fbmem:
dma_free_coherent(&pdev->dev, fbi->fb.fix.smem_len,
fbi->fb.screen_base, fbi->fb.fix.smem_start);
-failed_free_io:
- iounmap(fbi->regbase);
return ret;
}
@@ -486,8 +482,6 @@ static int __devexit vt8500lcd_remove(struct platform_device *pdev)
dma_free_coherent(&pdev->dev, fbi->palette_size,
fbi->palette_cpu, fbi->palette_phys);
- iounmap(fbi->regbase);
-
return 0;
}
--
1.7.4.1
While at it, also fix the related return statements.
Signed-off-by: Tushar Behera <[email protected]>
---
drivers/video/vt8500lcdfb.c | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)
diff --git a/drivers/video/vt8500lcdfb.c b/drivers/video/vt8500lcdfb.c
index 5777adc..2438368 100644
--- a/drivers/video/vt8500lcdfb.c
+++ b/drivers/video/vt8500lcdfb.c
@@ -294,8 +294,7 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
+ sizeof(u32) * 16, GFP_KERNEL);
if (!fbi) {
dev_err(&pdev->dev, "Failed to initialize framebuffer device\n");
- ret = -ENOMEM;
- goto failed;
+ return -ENOMEM;
}
strcpy(fbi->fb.fix.id, "VT8500 LCD");
@@ -328,15 +327,13 @@ static int __devinit vt8500lcd_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "no I/O memory resource defined\n");
- ret = -ENODEV;
- goto failed_fbi;
+ return -ENODEV;
}
res = request_mem_region(res->start, resource_size(res), "vt8500lcd");
if (res == NULL) {
dev_err(&pdev->dev, "failed to request I/O memory\n");
- ret = -EBUSY;
- goto failed_fbi;
+ return -EBUSY;
}
fbi->regbase = ioremap(res->start, resource_size(res));
@@ -466,10 +463,6 @@ failed_free_io:
iounmap(fbi->regbase);
failed_free_res:
release_mem_region(res->start, resource_size(res));
-failed_fbi:
- platform_set_drvdata(pdev, NULL);
- kfree(fbi);
-failed:
return ret;
}
@@ -501,8 +494,6 @@ static int __devexit vt8500lcd_remove(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
- kfree(fbi);
-
return 0;
}
--
1.7.4.1