linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis
@ 2012-11-22  6:42 Tushar Behera
  2012-11-22  6:42 ` [PATCH 1/4] video: vt8500: Fix memory leak in probe function Tushar Behera
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-22  6:42 UTC (permalink / raw)
  To: linux-kernel, linux-fbdev; +Cc: FlorianSchandinat, linux, patches

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


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

* [PATCH 1/4] video: vt8500: Fix memory leak in probe function
  2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
@ 2012-11-22  6:42 ` Tushar Behera
  2012-11-22  6:42 ` [PATCH 2/4] video: vt8500: Fix invalid free of devm_ allocated data Tushar Behera
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-22  6:42 UTC (permalink / raw)
  To: linux-kernel, linux-fbdev; +Cc: FlorianSchandinat, linux, patches

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 <tushar.behera@linaro.org>
---
 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


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

* [PATCH 2/4] video: vt8500: Fix invalid free of devm_ allocated data
  2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
  2012-11-22  6:42 ` [PATCH 1/4] video: vt8500: Fix memory leak in probe function Tushar Behera
@ 2012-11-22  6:42 ` Tushar Behera
  2012-11-22  6:42 ` [PATCH 3/4] video: vt8500: Convert to use devm_request_mem_region() Tushar Behera
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-22  6:42 UTC (permalink / raw)
  To: linux-kernel, linux-fbdev; +Cc: FlorianSchandinat, linux, patches

While at it, also fix the related return statements.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
 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


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

* [PATCH 3/4] video: vt8500: Convert to use devm_request_mem_region()
  2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
  2012-11-22  6:42 ` [PATCH 1/4] video: vt8500: Fix memory leak in probe function Tushar Behera
  2012-11-22  6:42 ` [PATCH 2/4] video: vt8500: Fix invalid free of devm_ allocated data Tushar Behera
@ 2012-11-22  6:42 ` Tushar Behera
  2012-11-22  6:42 ` [PATCH 4/4] video: vt8500: Convert to use devm_ioremap() Tushar Behera
  2012-11-22 18:07 ` [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tony Prisk
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-22  6:42 UTC (permalink / raw)
  To: linux-kernel, linux-fbdev; +Cc: FlorianSchandinat, linux, patches

While at it, fix the return statements.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
 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


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

* [PATCH 4/4] video: vt8500: Convert to use devm_ioremap()
  2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
                   ` (2 preceding siblings ...)
  2012-11-22  6:42 ` [PATCH 3/4] video: vt8500: Convert to use devm_request_mem_region() Tushar Behera
@ 2012-11-22  6:42 ` Tushar Behera
  2012-11-22 18:07 ` [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tony Prisk
  4 siblings, 0 replies; 6+ messages in thread
From: Tushar Behera @ 2012-11-22  6:42 UTC (permalink / raw)
  To: linux-kernel, linux-fbdev; +Cc: FlorianSchandinat, linux, patches

While at it, fix the return statements.

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
---
 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


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

* Re: [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis
  2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
                   ` (3 preceding siblings ...)
  2012-11-22  6:42 ` [PATCH 4/4] video: vt8500: Convert to use devm_ioremap() Tushar Behera
@ 2012-11-22 18:07 ` Tony Prisk
  4 siblings, 0 replies; 6+ messages in thread
From: Tony Prisk @ 2012-11-22 18:07 UTC (permalink / raw)
  To: Tushar Behera; +Cc: linux-kernel, linux-fbdev, FlorianSchandinat, patches

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 <linux@prisktech.co.nz>



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

end of thread, other threads:[~2012-11-22 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22  6:42 [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tushar Behera
2012-11-22  6:42 ` [PATCH 1/4] video: vt8500: Fix memory leak in probe function Tushar Behera
2012-11-22  6:42 ` [PATCH 2/4] video: vt8500: Fix invalid free of devm_ allocated data Tushar Behera
2012-11-22  6:42 ` [PATCH 3/4] video: vt8500: Convert to use devm_request_mem_region() Tushar Behera
2012-11-22  6:42 ` [PATCH 4/4] video: vt8500: Convert to use devm_ioremap() Tushar Behera
2012-11-22 18:07 ` [PATCH 0/4] video: vt8500: cleanup and use of devm_ apis Tony Prisk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).