Skip to contentSkip to conversation

media: davinci: vpif trivial cleanup

PATCH Superseded Prabhakar Lad 3 participants 19 messages May 26, 2013 – May 29, 2013 Media (V4L/DVB)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover media: davinci: vpif trivial cleanup

From: Lad, Prabhakar <[email protected]>

This patch series cleans the VPIF driver, uses devm_* api wherever required and uses module_platform_driver() to simplify the code.

This patch series applies on http://git.linuxtv.org/hverkuil/media_tree.git/
shortlog/refs/heads/for-v3.11 and is tested on OMAP-L138.

Changes for v2:
1: Rebased on v3.11 branch of Hans.
2: Dropped the patches which removed headers as mentioned by Laurent.

Changes for v3:
1: Splitted the patches logically as mentioned by Laurent. 2: Fixed review comments pointed by Laurent.
3: Included Ack's.

Lad, Prabhakar (9):
media: davinci: vpif: remove unwanted header mach/hardware.h and sort
the includes alphabetically
media: davinci: vpif: Convert to devm_* api
media: davinci: vpif: remove unnecessary braces around defines
media: davinci: vpif_capture: move the freeing of irq and global
variables to remove()
media: davinci: vpif_capture: use module_platform_driver()
media: davinci: vpif_capture: Convert to devm_* api
media: davinci: vpif_display: move the freeing of irq and global
variables to remove()
media: davinci: vpif_display: use module_platform_driver()
media: davinci: vpif_display: Convert to devm_* api

 drivers/media/platform/davinci/vpif.c         |   45 ++++-----------
 drivers/media/platform/davinci/vpif_capture.c |   75 +++++--------------------
 drivers/media/platform/davinci/vpif_display.c |   63 ++++----------------
 3 files changed, 40 insertions(+), 143 deletions(-)
#1 lore raw

PATCH v3 1/9 media: davinci: vpif: remove unwanted header mach/hardware.h and sort the includes alphabetically

From: Lad, Prabhakar <[email protected]>

This patch removes unwanted header include of mach/hardware.h and along side sorts the header inclusion alphabetically.

---
 drivers/media/platform/davinci/vpif.c |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)
drivers/media/platform/davinci/vpif.c +4 -6
index ea82a8b..761c825 100644
@@ -17,18 +17,16 @@
  * GNU General Public License for more details.
  */
 
+#include <linux/err.h>
 #include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
-#include <linux/spinlock.h>
-#include <linux/kernel.h>
-#include <linux/io.h>
-#include <linux/err.h>
 #include <linux/pm_runtime.h>
+#include <linux/spinlock.h>
 #include <linux/v4l2-dv-timings.h>
 
-#include <mach/hardware.h>
-
 #include "vpif.h"
 
 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v3 2/9 media: davinci: vpif: Convert to devm_* api

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

Use devm_ioremap_resource instead of reques_mem_region()/ioremap(). This ensures more consistent error values and simplifies error paths.

---
 drivers/media/platform/davinci/vpif.c |   27 ++++-----------------------
 1 files changed, 4 insertions(+), 23 deletions(-)
drivers/media/platform/davinci/vpif.c +4 -23
index 761c825..f857d8f 100644
@@ -37,8 +37,6 @@ MODULE_LICENSE("GPL");
 #define VPIF_CH2_MAX_MODES	(15)
 #define VPIF_CH3_MAX_MODES	(02)
 
-static resource_size_t	res_len;
-static struct resource	*res;
 spinlock_t vpif_lock;
 
 void __iomem *vpif_base;
@@ -421,23 +419,12 @@ EXPORT_SYMBOL(vpif_channel_getfid);
 
 static int vpif_probe(struct platform_device *pdev)
 {
-	int status = 0;
+	static struct resource	*res;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENOENT;
-
-	res_len = resource_size(res);
-
-	res = request_mem_region(res->start, res_len, res->name);
-	if (!res)
-		return -EBUSY;
-
-	vpif_base = ioremap(res->start, res_len);
-	if (!vpif_base) {
-		status = -EBUSY;
-		goto fail;
-	}
+	vpif_base = devm_request_and_ioremap(&pdev->dev, res);
+	if (IS_ERR(vpif_base))
+		return PTR_ERR(vpif_base);
 
 	pm_runtime_enable(&pdev->dev);
 	pm_runtime_get(&pdev->dev);
@@ -445,17 +432,11 @@ static int vpif_probe(struct platform_device *pdev)
 	spin_lock_init(&vpif_lock);
 	dev_info(&pdev->dev, "vpif probe success\n");
 	return 0;
-
-fail:
-	release_mem_region(res->start, res_len);
-	return status;
 }
 
 static int vpif_remove(struct platform_device *pdev)
 {
 	pm_runtime_disable(&pdev->dev);
-	iounmap(vpif_base);
-	release_mem_region(res->start, res_len);
 	return 0;
 }
 
Signature · 1 line
1.7.0.4
#3 lore raw

Re: [PATCH v3 2/9] media: davinci: vpif: Convert to devm_* api

Hello.

Quoted 15 lines · Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

Use devm_ioremap_resource instead of reques_mem_region()/ioremap(). This ensures more consistent error values and simplifies error paths.

---
  drivers/media/platform/davinci/vpif.c |   27 ++++-----------------------
  1 files changed, 4 insertions(+), 23 deletions(-)
drivers/media/platform/davinci/vpif.c +0 -0
index 761c825..f857d8f 100644

[...]

Quoted 8 lines
drivers/media/platform/davinci/vpif.c +1 -1
@@ -421,23 +419,12 @@ EXPORT_SYMBOL(vpif_channel_getfid);
 
  static int vpif_probe(struct platform_device *pdev)
  {
-	int status = 0;
+	static struct resource	*res;
 
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

[...]

drivers/media/platform/davinci/vpif.c EXPORT_SYMBOL(vpif_channel_getfid); · line 425

Quoted 1 line
drivers/media/platform/davinci/vpif.c +1 -0
+	vpif_base = devm_request_and_ioremap(&pdev->dev, res);

No, don't use this deprecated funtion please. Undo to
devm_ioremap_resource().

drivers/media/platform/davinci/vpif.c EXPORT_SYMBOL(vpif_channel_getfid); · line 426

Quoted 1 line
drivers/media/platform/davinci/vpif.c +1 -0
+	if (IS_ERR(vpif_base))

NAK, devm_request_and_ioremap() doesn't rethrn error cpdes, only
NULL. BTW, it's implemented via a call to devm_ioremap_resource() now. Is it so hard to look at the code that you've calling?

drivers/media/platform/davinci/vpif.c EXPORT_SYMBOL(vpif_channel_getfid); · line 427

Quoted 1 line
drivers/media/platform/davinci/vpif.c +1 -0
+		return PTR_ERR(vpif_base);

WBR, Sergei

#4 lore raw

PATCH v3 3/9 media: davinci: vpif: remove unnecessary braces around defines

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

This patch removes unnecessary braces around defines.

---
 drivers/media/platform/davinci/vpif.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/davinci/vpif.c +4 -4
index f857d8f..77763f1 100644
@@ -32,10 +32,10 @@
 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
 MODULE_LICENSE("GPL");
 
-#define VPIF_CH0_MAX_MODES	(22)
-#define VPIF_CH1_MAX_MODES	(02)
-#define VPIF_CH2_MAX_MODES	(15)
-#define VPIF_CH3_MAX_MODES	(02)
+#define VPIF_CH0_MAX_MODES	22
+#define VPIF_CH1_MAX_MODES	2
+#define VPIF_CH2_MAX_MODES	15
+#define VPIF_CH3_MAX_MODES	2
 
 spinlock_t vpif_lock;
 
Signature · 1 line
1.7.0.4
#5 lore raw

PATCH v3 4/9 media: davinci: vpif_capture: move the freeing of irq and global variables to remove()

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

Ideally the freeing of irq's and the global variables needs to be done in the remove() rather than module_exit(), this patch moves the freeing up of irq's and freeing the memory allocated to channel objects to remove() callback of struct platform_driver.

---
 drivers/media/platform/davinci/vpif_capture.c |   31 ++++++++++--------------
 1 files changed, 13 insertions(+), 18 deletions(-)
drivers/media/platform/davinci/vpif_capture.c +13 -18
index caaf4fe..f8b7304 100644
@@ -2225,17 +2225,29 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	int i;
+	struct platform_device *pdev;
 	struct channel_obj *ch;
+	struct resource *res;
+	int irq_num, i = 0;
+
+	pdev = container_of(vpif_dev, struct platform_device, dev);
+	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
+		for (irq_num = res->start; irq_num <= res->end; irq_num++)
+			free_irq(irq_num,
+				 (void *)(&vpif_obj.dev[i]->channel_id));
+		i++;
+	}
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
+	kfree(vpif_obj.sd);
 	/* un-register device */
 	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
 		/* Get the pointer to the channel object */
 		ch = vpif_obj.dev[i];
 		/* Unregister video device */
 		video_unregister_device(ch->video_dev);
+		kfree(vpif_obj.dev[i]);
 	}
 	return 0;
 }
@@ -2347,24 +2359,7 @@ static __init int vpif_init(void)
  */
 static void vpif_cleanup(void)
 {
-	struct platform_device *pdev;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	platform_driver_unregister(&vpif_driver);
-
-	kfree(vpif_obj.sd);
-	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
-		kfree(vpif_obj.dev[i]);
 }
 
 /* Function for module initialization and cleanup */
Signature · 1 line
1.7.0.4
#6 lore raw

Re: [PATCH v3 4/9] media: davinci: vpif_capture: move the freeing of irq and global variables to remove()

Hello.

Quoted 17 lines · Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

Ideally the freeing of irq's and the global variables needs to be done in the remove() rather than module_exit(), this patch moves the freeing up of irq's and freeing the memory allocated to channel objects to remove() callback of struct platform_driver.

---
  drivers/media/platform/davinci/vpif_capture.c |   31 ++++++++++--------------
  1 files changed, 13 insertions(+), 18 deletions(-)
drivers/media/platform/davinci/vpif_capture.c +0 -0
index caaf4fe..f8b7304 100644

drivers/media/platform/davinci/vpif_capture.c vpif_int_err: · line 2233

Quoted 10 lines
drivers/media/platform/davinci/vpif_capture.c +5 -1
@@ -2225,17 +2225,29 @@ vpif_int_err:
   */
  static int vpif_remove(struct platform_device *device)
  {
-	int i;
+	struct platform_device *pdev;
  	struct channel_obj *ch;
+	struct resource *res;
+	int irq_num, i = 0;
+
+	pdev = container_of(vpif_dev, struct platform_device, dev);

Why you need this if you should be already called with the correct
platform device?

WBR, Sergei

#7 lore raw

Re: [PATCH v3 4/9] media: davinci: vpif_capture: move the freeing of irq and global variables to remove()

In reply to Prabhakar Lad

Hi Prabhakar,

Thanks for the patch.

Quoted 18 lines · On Sunday 26 May 2013 17:30:07 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

Ideally the freeing of irq's and the global variables needs to be done in the remove() rather than module_exit(), this patch moves the freeing up of irq's and freeing the memory allocated to channel objects to remove() callback of struct platform_driver.

---
 drivers/media/platform/davinci/vpif_capture.c |   31 ++++++++++------------
 1 files changed, 13 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_capture.c index caaf4fe..f8b7304 100644

drivers/media/platform/davinci/vpif_capture.c vpif_int_err: · line 2233

Quoted 10 lines
drivers/media/platform/davinci/vpif_capture.c +5 -1
@@ -2225,17 +2225,29 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	int i;
+	struct platform_device *pdev;
 	struct channel_obj *ch;
+	struct resource *res;
+	int irq_num, i = 0;
+
+	pdev = container_of(vpif_dev, struct platform_device, dev);

As Sergei mentioned, the platform device is already passed to the function as an argument.

drivers/media/platform/davinci/vpif_capture.c vpif_int_err: · line 2237

Quoted 4 lines
drivers/media/platform/davinci/vpif_capture.c +4 -0
+	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
+		for (irq_num = res->start; irq_num <= res->end; irq_num++)
+			free_irq(irq_num,
+				 (void *)(&vpif_obj.dev[i]->channel_id));

A quick look at board code shows that each IRQ resource contains a single IRQ. The second loop could thus be removed. You could also add another patch to perform similar cleanup for the probe code.

Quoted 41 lines
drivers/media/platform/davinci/vpif_capture.c +4 -17
+		i++;
+	}
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
+	kfree(vpif_obj.sd);
 	/* un-register device */
 	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++) {
 		/* Get the pointer to the channel object */
 		ch = vpif_obj.dev[i];
 		/* Unregister video device */
 		video_unregister_device(ch->video_dev);
+		kfree(vpif_obj.dev[i]);
 	}
 	return 0;
 }
@@ -2347,24 +2359,7 @@ static __init int vpif_init(void)
  */
 static void vpif_cleanup(void)
 {
-	struct platform_device *pdev;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	platform_driver_unregister(&vpif_driver);
-
-	kfree(vpif_obj.sd);
-	for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
-		kfree(vpif_obj.dev[i]);
 }
 
 /* Function for module initialization and cleanup */
Signature · 3 lines
Regards,

Laurent Pinchart
#8 lore raw

Re: [PATCH v3 4/9] media: davinci: vpif_capture: move the freeing of irq and global variables to remove()

Hi Laurent,

Thanks for the review.

Quoted 28 lines · Laurent Pinchart

Hi Prabhakar,

Thanks for the patch.

Quoted 23 lines · On Sunday 26 May 2013 17:30:07 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

Ideally the freeing of irq's and the global variables needs to be done in the remove() rather than module_exit(), this patch moves the freeing up of irq's and freeing the memory allocated to channel objects to remove() callback of struct platform_driver.

---
 drivers/media/platform/davinci/vpif_capture.c |   31 ++++++++++------------
 1 files changed, 13 insertions(+), 18 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_capture.c index caaf4fe..f8b7304 100644

drivers/media/platform/davinci/vpif_capture.c +1 -1
@@ -2225,17 +2225,29 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-     int i;
+     struct platform_device *pdev;
Quoted 9 lines

drivers/media/platform/davinci/vpif_capture.c vpif_int_err: · line 2233

Quoted 5 lines
drivers/media/platform/davinci/vpif_capture.c +4 -0
      struct channel_obj *ch;
+     struct resource *res;
+     int irq_num, i = 0;
+
+     pdev = container_of(vpif_dev, struct platform_device, dev);

As Sergei mentioned, the platform device is already passed to the function as an argument.

OK

Quoted 9 lines

drivers/media/platform/davinci/vpif_capture.c vpif_int_err: · line 2237

Quoted 4 lines
drivers/media/platform/davinci/vpif_capture.c +4 -0
+     while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
+             for (irq_num = res->start; irq_num <= res->end; irq_num++)
+                     free_irq(irq_num,
+                              (void *)(&vpif_obj.dev[i]->channel_id));

A quick look at board code shows that each IRQ resource contains a single IRQ. The second loop could thus be removed. You could also add another patch to perform similar cleanup for the probe code.

Any way this will code will be removed in the next patch of the same series due to usage
of devm_* api. I'll do this change only in the probe code.

Regards,
--Prabhakar Lad

#9 lore raw

PATCH v3 5/9 media: davinci: vpif_capture: use module_platform_driver()

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

This patch uses module_platform_driver() to simplify the code.

---
 drivers/media/platform/davinci/vpif_capture.c |   28 +------------------------
 1 files changed, 1 insertions(+), 27 deletions(-)
drivers/media/platform/davinci/vpif_capture.c +1 -27
index f8b7304..38c1fba 100644
@@ -2338,30 +2338,4 @@ static __refdata struct platform_driver vpif_driver = {
 	.remove = vpif_remove,
 };
 
-/**
- * vpif_init: initialize the vpif driver
- *
- * This function registers device and driver to the kernel, requests irq
- * handler and allocates memory
- * for channel objects
- */
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/**
- * vpif_cleanup : This function clean up the vpif capture resources
- *
- * This will un-registers device and driver to the kernel, frees
- * requested irq handler and de-allocates memory allocated for channel
- * objects.
- */
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-/* Function for module initialization and cleanup */
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
Signature · 1 line
1.7.0.4
Acked-by on v3 5/9
#10 lore raw

Re: [PATCH v3 5/9] media: davinci: vpif_capture: use module_platform_driver()

Quoted 5 lines · On Sunday 26 May 2013 17:30:08 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

This patch uses module_platform_driver() to simplify the code.

Quoted 41 lines
---
 drivers/media/platform/davinci/vpif_capture.c |   28 +---------------------
 1 files changed, 1 insertions(+), 27 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_capture.c index f8b7304..38c1fba 100644

drivers/media/platform/davinci/vpif_capture.c +1 -27
@@ -2338,30 +2338,4 @@ static __refdata struct platform_driver vpif_driver =
 { .remove = vpif_remove,
 };
 
-/**
- * vpif_init: initialize the vpif driver
- *
- * This function registers device and driver to the kernel, requests irq
- * handler and allocates memory
- * for channel objects
- */
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/**
- * vpif_cleanup : This function clean up the vpif capture resources
- *
- * This will un-registers device and driver to the kernel, frees
- * requested irq handler and de-allocates memory allocated for channel
- * objects.
- */
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-/* Function for module initialization and cleanup */
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
Signature · 3 lines
Regards,

Laurent Pinchart
#11 lore raw

PATCH v3 6/9 media: davinci: vpif_capture: Convert to devm_* api

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

use devm_request_irq() instead of request_irq(). This ensures more consistent error values and simplifies error paths.

---
 drivers/media/platform/davinci/vpif_capture.c |   38 ++++++++-----------------
 1 files changed, 12 insertions(+), 26 deletions(-)
drivers/media/platform/davinci/vpif_capture.c +12 -26
index 38c1fba..5e1e5f6 100644
@@ -2082,14 +2082,14 @@ static __init int vpif_probe(struct platform_device *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Capture", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
-				goto vpif_int_err;
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Capture",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
+				goto vpif_unregister;
+
 			}
 		}
 		res_idx++;
@@ -2106,7 +2106,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 				video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -2207,13 +2207,9 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
+
 	return err;
 }
 
@@ -2225,18 +2221,8 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	struct platform_device *pdev;
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num, i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
+	int i;
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
Signature · 1 line
1.7.0.4
Acked-by on v3 6/9
#12 lore raw

Re: [PATCH v3 6/9] media: davinci: vpif_capture: Convert to devm_* api

Quoted 6 lines · On Sunday 26 May 2013 17:30:09 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

use devm_request_irq() instead of request_irq(). This ensures more consistent error values and simplifies error paths.

Quoted 77 lines
---
 drivers/media/platform/davinci/vpif_capture.c |   38 ++++++++--------------
 1 files changed, 12 insertions(+), 26 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_capture.c index 38c1fba..5e1e5f6 100644

drivers/media/platform/davinci/vpif_capture.c +8 -8
@@ -2082,14 +2082,14 @@ static __init int vpif_probe(struct platform_device
 *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Capture", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
-				goto vpif_int_err;
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Capture",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
+				goto vpif_unregister;
+
 			}
 		}
drivers/media/platform/davinci/vpif_capture.c +4 -18
 		res_idx++;
@@ -2106,7 +2106,7 @@ static __init int vpif_probe(struct platform_device
 *pdev) video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -2207,13 +2207,9 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
+
 	return err;
 }
 
@@ -2225,18 +2221,8 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	struct platform_device *pdev;
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num, i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
+	int i;
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
Signature · 3 lines
Regards,

Laurent Pinchart
#13 lore raw

PATCH v3 7/9 media: davinci: vpif_display: move the freeing of irq and global variables to remove()

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

Ideally the freeing of irq's and the global variables needs to be done in the remove() rather than module_exit(), this patch moves the freeing up of irq's and freeing the memory allocated to channel objects to remove() callback of struct platform_driver.

---
 drivers/media/platform/davinci/vpif_display.c |   32 +++++++++++--------------
 1 files changed, 14 insertions(+), 18 deletions(-)
drivers/media/platform/davinci/vpif_display.c +14 -18
index 5b6f906..9c308e7 100644
@@ -1894,11 +1894,23 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
+	struct platform_device *pdev;
 	struct channel_obj *ch;
-	int i;
+	struct resource *res;
+	int irq_num;
+	int i = 0;
+
+	pdev = container_of(vpif_dev, struct platform_device, dev);
+	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
+		for (irq_num = res->start; irq_num <= res->end; irq_num++)
+			free_irq(irq_num,
+				 (void *)(&vpif_obj.dev[i]->channel_id));
+		i++;
+	}
 
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
+	kfree(vpif_obj.sd);
 	/* un-register device */
 	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++) {
 		/* Get the pointer to the channel object */
@@ -1907,6 +1919,7 @@ static int vpif_remove(struct platform_device *device)
 		video_unregister_device(ch->video_dev);
 
 		ch->video_dev = NULL;
+		kfree(vpif_obj.dev[i]);
 	}
 
 	return 0;
@@ -2004,24 +2017,7 @@ static __init int vpif_init(void)
  */
 static void vpif_cleanup(void)
 {
-	struct platform_device *pdev;
-	struct resource *res;
-	int irq_num;
-	int i = 0;
-
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	platform_driver_unregister(&vpif_driver);
-	kfree(vpif_obj.sd);
-	for (i = 0; i < VPIF_DISPLAY_MAX_DEVICES; i++)
-		kfree(vpif_obj.dev[i]);
 }
 
 module_init(vpif_init);
Signature · 1 line
1.7.0.4
#14 lore raw

PATCH v3 8/9 media: davinci: vpif_display: use module_platform_driver()

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

This patch uses module_platform_driver() to simplify the code.

---
 drivers/media/platform/davinci/vpif_display.c |   18 +-----------------
 1 files changed, 1 insertions(+), 17 deletions(-)
drivers/media/platform/davinci/vpif_display.c +1 -17
index 9c308e7..7bcfe7d 100644
@@ -2005,20 +2005,4 @@ static __refdata struct platform_driver vpif_driver = {
 	.remove	= vpif_remove,
 };
 
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/*
- * vpif_cleanup: This function un-registers device and driver to the kernel,
- * frees requested irq handler and de-allocates memory allocated for channel
- * objects.
- */
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
Signature · 1 line
1.7.0.4
Acked-by on v3 8/9
#15 lore raw

Re: [PATCH v3 8/9] media: davinci: vpif_display: use module_platform_driver()

Quoted 5 lines · On Sunday 26 May 2013 17:30:11 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

This patch uses module_platform_driver() to simplify the code.

Quoted 31 lines
---
 drivers/media/platform/davinci/vpif_display.c |   18 +-----------------
 1 files changed, 1 insertions(+), 17 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_display.c index 9c308e7..7bcfe7d 100644

drivers/media/platform/davinci/vpif_display.c +0 -7
@@ -2005,20 +2005,4 @@ static __refdata struct platform_driver vpif_driver =
 { .remove	= vpif_remove,
 };
 
-static __init int vpif_init(void)
-{
-	return platform_driver_register(&vpif_driver);
-}
-
-/*
- * vpif_cleanup: This function un-registers device and driver to the

kernel, - * frees requested irq handler and de-allocates memory allocated for channel - * objects.
- */

drivers/media/platform/davinci/vpif_display.c +1 -7
-static void vpif_cleanup(void)
-{
-	platform_driver_unregister(&vpif_driver);
-}
-
-module_init(vpif_init);
-module_exit(vpif_cleanup);
+module_platform_driver(vpif_driver);
Signature · 3 lines
Regards,

Laurent Pinchart
#16 lore raw

PATCH v3 9/9 media: davinci: vpif_display: Convert to devm_* api

In reply to Prabhakar Lad

From: Lad, Prabhakar <[email protected]>

use devm_request_irq() instead of request_irq(). This ensures more consistent error values and simplifies error paths.

---
 drivers/media/platform/davinci/vpif_display.c |   35 ++++++------------------
 1 files changed, 9 insertions(+), 26 deletions(-)
drivers/media/platform/davinci/vpif_display.c +9 -26
index 7bcfe7d..e2f080b 100644
@@ -1718,15 +1718,14 @@ static __init int vpif_probe(struct platform_device *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Display", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Display",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
 				vpif_err("VPIF IRQ request failed\n");
-				goto vpif_int_err;
+				goto vpif_unregister;
 			}
 		}
 		res_idx++;
@@ -1744,7 +1743,7 @@ static __init int vpif_probe(struct platform_device *pdev)
 				video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -1878,13 +1877,8 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
 
 	return err;
 }
@@ -1894,20 +1888,9 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	struct platform_device *pdev;
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num;
 	int i = 0;
 
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
 	kfree(vpif_obj.sd);
Signature · 1 line
1.7.0.4
Acked-by on v3 9/9
#17 lore raw

Re: [PATCH v3 9/9] media: davinci: vpif_display: Convert to devm_* api

Quoted 6 lines · On Sunday 26 May 2013 17:30:12 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

use devm_request_irq() instead of request_irq(). This ensures more consistent error values and simplifies error paths.

with a small comment below.

Quoted 58 lines
---
 drivers/media/platform/davinci/vpif_display.c |   35 ++++++----------------
 1 files changed, 9 insertions(+), 26 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_display.c index 7bcfe7d..e2f080b 100644

drivers/media/platform/davinci/vpif_display.c +7 -8
@@ -1718,15 +1718,14 @@ static __init int vpif_probe(struct platform_device
 *pdev)
 
 	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
 		for (i = res->start; i <= res->end; i++) {
-			if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-					"VPIF_Display", (void *)
-					(&vpif_obj.dev[res_idx]->channel_id))) {
-				err = -EBUSY;
-				for (j = 0; j < i; j++)
-					free_irq(j, (void *)
-					(&vpif_obj.dev[res_idx]->channel_id));
+			err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+					     IRQF_SHARED, "VPIF_Display",
+					     (void *)(&vpif_obj.dev[res_idx]->
+					     channel_id));
+			if (err) {
+				err = -EINVAL;
 				vpif_err("VPIF IRQ request failed\n");
-				goto vpif_int_err;
+				goto vpif_unregister;
 			}
 		}
drivers/media/platform/davinci/vpif_display.c +2 -7
 		res_idx++;
@@ -1744,7 +1743,7 @@ static __init int vpif_probe(struct platform_device
 *pdev) video_device_release(ch->video_dev);
 			}
 			err = -ENOMEM;
-			goto vpif_int_err;
+			goto vpif_unregister;
 		}
 
 		/* Initialize field of video device */
@@ -1878,13 +1877,8 @@ vpif_sd_error:
 		/* Note: does nothing if ch->video_dev == NULL */
 		video_device_release(ch->video_dev);
 	}
-vpif_int_err:
+vpif_unregister:
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
-	for (i = 0; i < res_idx; i++) {
-		res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-		for (j = res->start; j <= res->end; j++)
-			free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-	}
 
 	return err;
 }

drivers/media/platform/davinci/vpif_display.c vpif_int_err: · line 1892

Quoted 8 lines
drivers/media/platform/davinci/vpif_display.c +0 -3
@@ -1894,20 +1888,9 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-	struct platform_device *pdev;
 	struct channel_obj *ch;
-	struct resource *res;
-	int irq_num;
 	int i = 0;

There's no need to initialize i to 0 anymore (same comment for patch 6/9).

Quoted 11 lines
drivers/media/platform/davinci/vpif_display.c +0 -8
-	pdev = container_of(vpif_dev, struct platform_device, dev);
-	while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, i))) {
-		for (irq_num = res->start; irq_num <= res->end; irq_num++)
-			free_irq(irq_num,
-				 (void *)(&vpif_obj.dev[i]->channel_id));
-		i++;
-	}
-
 	v4l2_device_unregister(&vpif_obj.v4l2_dev);
 
 	kfree(vpif_obj.sd);
Signature · 3 lines
Regards,

Laurent Pinchart
#18 lore raw

Re: [PATCH v3 9/9] media: davinci: vpif_display: Convert to devm_* api

Hi Laurent,

Quoted 10 lines · Laurent Pinchart
Quoted 6 lines · On Sunday 26 May 2013 17:30:12 Prabhakar Lad wrote:

From: Lad, Prabhakar <[email protected]>

use devm_request_irq() instead of request_irq(). This ensures more consistent error values and simplifies error paths.

Thanks for the ack.

Quoted 57 lines

with a small comment below.

Quoted 55 lines
---
 drivers/media/platform/davinci/vpif_display.c |   35 ++++++----------------
 1 files changed, 9 insertions(+), 26 deletions(-)
(quoted diff) +0 -0

b/drivers/media/platform/davinci/vpif_display.c index 7bcfe7d..e2f080b 100644

drivers/media/platform/davinci/vpif_display.c +7 -8
@@ -1718,15 +1718,14 @@ static __init int vpif_probe(struct platform_device
 *pdev)
 
      while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
              for (i = res->start; i <= res->end; i++) {
-                     if (request_irq(i, vpif_channel_isr, IRQF_SHARED,
-                                     "VPIF_Display", (void *)
-                                     (&vpif_obj.dev[res_idx]->channel_id))) {
-                             err = -EBUSY;
-                             for (j = 0; j < i; j++)
-                                     free_irq(j, (void *)
-                                     (&vpif_obj.dev[res_idx]->channel_id));
+                     err = devm_request_irq(&pdev->dev, i, vpif_channel_isr,
+                                          IRQF_SHARED, "VPIF_Display",
+                                          (void *)(&vpif_obj.dev[res_idx]->
+                                          channel_id));
+                     if (err) {
+                             err = -EINVAL;
                              vpif_err("VPIF IRQ request failed\n");
-                             goto vpif_int_err;
+                             goto vpif_unregister;
                      }
              }
              res_idx++;
drivers/media/platform/davinci/vpif_display.c +2 -7
@@ -1744,7 +1743,7 @@ static __init int vpif_probe(struct platform_device
 *pdev) video_device_release(ch->video_dev);
                      }
                      err = -ENOMEM;
-                     goto vpif_int_err;
+                     goto vpif_unregister;
              }
 
              /* Initialize field of video device */
@@ -1878,13 +1877,8 @@ vpif_sd_error:
              /* Note: does nothing if ch->video_dev == NULL */
              video_device_release(ch->video_dev);
      }
-vpif_int_err:
+vpif_unregister:
      v4l2_device_unregister(&vpif_obj.v4l2_dev);
-     for (i = 0; i < res_idx; i++) {
-             res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
-             for (j = res->start; j <= res->end; j++)
-                     free_irq(j, (void *)(&vpif_obj.dev[i]->channel_id));
-     }
 
Quoted 14 lines

drivers/media/platform/davinci/vpif_display.c vpif_int_err: · line 1892

Quoted 11 lines
drivers/media/platform/davinci/vpif_display.c +0 -3
      return err;
 }
@@ -1894,20 +1888,9 @@ vpif_int_err:
  */
 static int vpif_remove(struct platform_device *device)
 {
-     struct platform_device *pdev;
      struct channel_obj *ch;
-     struct resource *res;
-     int irq_num;
      int i = 0;

There's no need to initialize i to 0 anymore (same comment for patch 6/9).

Ok will fix it in the next version.

Regards,
--Prabhakar Lad