[media] s5p-jpeg: Use devm_* functions in jpeg-core.c file
authorSachin Kamat <sachin.kamat@linaro.org>
Mon, 14 May 2012 09:33:34 +0000 (06:33 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Sun, 20 May 2012 12:05:44 +0000 (09:05 -0300)
devm_* functions are used to replace kzalloc, request_mem_region, ioremap
and request_irq functions in probe call. With the usage of devm_* functions
explicit freeing and unmapping is not required.

Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
drivers/media/video/s5p-jpeg/jpeg-core.c
drivers/media/video/s5p-jpeg/jpeg-core.h

index 2d7dd8ac73f38af008fd7f3c039ce99f9ceb6930..28b5225d94f588bfc5387ec62a41a6ee960eec50 100644 (file)
@@ -1290,7 +1290,7 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
        int ret;
 
        /* JPEG IP abstraction struct */
-       jpeg = kzalloc(sizeof(struct s5p_jpeg), GFP_KERNEL);
+       jpeg = devm_kzalloc(&pdev->dev, sizeof(struct s5p_jpeg), GFP_KERNEL);
        if (!jpeg)
                return -ENOMEM;
 
@@ -1300,43 +1300,25 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
 
        /* memory-mapped registers */
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (!res) {
-               dev_err(&pdev->dev, "cannot find IO resource\n");
-               ret = -ENOENT;
-               goto jpeg_alloc_rollback;
-       }
-
-       jpeg->ioarea = request_mem_region(res->start, resource_size(res),
-                                         pdev->name);
-       if (!jpeg->ioarea) {
-               dev_err(&pdev->dev, "cannot request IO\n");
-               ret = -ENXIO;
-               goto jpeg_alloc_rollback;
-       }
 
-       jpeg->regs = ioremap(res->start, resource_size(res));
-       if (!jpeg->regs) {
-               dev_err(&pdev->dev, "cannot map IO\n");
-               ret = -ENXIO;
-               goto mem_region_rollback;
+       jpeg->regs = devm_request_and_ioremap(&pdev->dev, res);
+       if (jpeg->regs == NULL) {
+               dev_err(&pdev->dev, "Failed to obtain io memory\n");
+               return -ENOENT;
        }
 
-       dev_dbg(&pdev->dev, "registers %p (%p, %p)\n",
-               jpeg->regs, jpeg->ioarea, res);
-
        /* interrupt service routine registration */
        jpeg->irq = ret = platform_get_irq(pdev, 0);
        if (ret < 0) {
                dev_err(&pdev->dev, "cannot find IRQ\n");
-               goto ioremap_rollback;
+               return ret;
        }
 
-       ret = request_irq(jpeg->irq, s5p_jpeg_irq, 0,
-                         dev_name(&pdev->dev), jpeg);
-
+       ret = devm_request_irq(&pdev->dev, jpeg->irq, s5p_jpeg_irq, 0,
+                       dev_name(&pdev->dev), jpeg);
        if (ret) {
                dev_err(&pdev->dev, "cannot claim IRQ %d\n", jpeg->irq);
-               goto ioremap_rollback;
+               return ret;
        }
 
        /* clocks */
@@ -1344,7 +1326,7 @@ static int s5p_jpeg_probe(struct platform_device *pdev)
        if (IS_ERR(jpeg->clk)) {
                dev_err(&pdev->dev, "cannot get clock\n");
                ret = PTR_ERR(jpeg->clk);
-               goto request_irq_rollback;
+               return ret;
        }
        dev_dbg(&pdev->dev, "clock source %p\n", jpeg->clk);
        clk_enable(jpeg->clk);
@@ -1464,18 +1446,6 @@ clk_get_rollback:
        clk_disable(jpeg->clk);
        clk_put(jpeg->clk);
 
-request_irq_rollback:
-       free_irq(jpeg->irq, jpeg);
-
-ioremap_rollback:
-       iounmap(jpeg->regs);
-
-mem_region_rollback:
-       release_resource(jpeg->ioarea);
-       release_mem_region(jpeg->ioarea->start, resource_size(jpeg->ioarea));
-
-jpeg_alloc_rollback:
-       kfree(jpeg);
        return ret;
 }
 
@@ -1496,14 +1466,6 @@ static int s5p_jpeg_remove(struct platform_device *pdev)
        clk_disable(jpeg->clk);
        clk_put(jpeg->clk);
 
-       free_irq(jpeg->irq, jpeg);
-
-       iounmap(jpeg->regs);
-
-       release_resource(jpeg->ioarea);
-       release_mem_region(jpeg->ioarea->start, resource_size(jpeg->ioarea));
-       kfree(jpeg);
-
        return 0;
 }
 
index 38d7367f7a6d15f9e9d8b9d57b096aea50390d87..9d0cd2b76f619e9d7b0c6321ae0c38b2ddeed28a 100644 (file)
@@ -54,7 +54,6 @@
  * @vfd_encoder:       video device node for encoder mem2mem mode
  * @vfd_decoder:       video device node for decoder mem2mem mode
  * @m2m_dev:           v4l2 mem2mem device data
- * @ioarea:            JPEG IP memory region
  * @regs:              JPEG IP registers mapping
  * @irq:               JPEG IP irq
  * @clk:               JPEG IP clock
@@ -70,7 +69,6 @@ struct s5p_jpeg {
        struct video_device     *vfd_decoder;
        struct v4l2_m2m_dev     *m2m_dev;
 
-       struct resource         *ioarea;
        void __iomem            *regs;
        unsigned int            irq;
        struct clk              *clk;