Commit 32fced05 authored by Sachin Kamat's avatar Sachin Kamat Committed by Mauro Carvalho Chehab

[media] s5p-g2d: Use devm_* functions in g2d.c file

devm_* functions are device managed functions and make error handling
and cleanup simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Signed-off-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 3e9095d5
...@@ -674,42 +674,27 @@ static int g2d_probe(struct platform_device *pdev) ...@@ -674,42 +674,27 @@ static int g2d_probe(struct platform_device *pdev)
struct resource *res; struct resource *res;
int ret = 0; int ret = 0;
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
spin_lock_init(&dev->ctrl_lock); spin_lock_init(&dev->ctrl_lock);
mutex_init(&dev->mutex); mutex_init(&dev->mutex);
atomic_set(&dev->num_inst, 0); atomic_set(&dev->num_inst, 0);
init_waitqueue_head(&dev->irq_queue); init_waitqueue_head(&dev->irq_queue);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "failed to find registers\n");
ret = -ENOENT;
goto free_dev;
}
dev->res_regs = request_mem_region(res->start, resource_size(res), dev->regs = devm_request_and_ioremap(&pdev->dev, res);
dev_name(&pdev->dev)); if (dev->regs == NULL) {
dev_err(&pdev->dev, "Failed to obtain io memory\n");
if (!dev->res_regs) { return -ENOENT;
dev_err(&pdev->dev, "failed to obtain register region\n");
ret = -ENOENT;
goto free_dev;
}
dev->regs = ioremap(res->start, resource_size(res));
if (!dev->regs) {
dev_err(&pdev->dev, "failed to map registers\n");
ret = -ENOENT;
goto rel_res_regs;
} }
dev->clk = clk_get(&pdev->dev, "sclk_fimg2d"); dev->clk = clk_get(&pdev->dev, "sclk_fimg2d");
if (IS_ERR_OR_NULL(dev->clk)) { if (IS_ERR_OR_NULL(dev->clk)) {
dev_err(&pdev->dev, "failed to get g2d clock\n"); dev_err(&pdev->dev, "failed to get g2d clock\n");
ret = -ENXIO; return -ENXIO;
goto unmap_regs;
} }
ret = clk_prepare(dev->clk); ret = clk_prepare(dev->clk);
...@@ -740,7 +725,8 @@ static int g2d_probe(struct platform_device *pdev) ...@@ -740,7 +725,8 @@ static int g2d_probe(struct platform_device *pdev)
dev->irq = res->start; dev->irq = res->start;
ret = request_irq(dev->irq, g2d_isr, 0, pdev->name, dev); ret = devm_request_irq(&pdev->dev, dev->irq, g2d_isr,
0, pdev->name, dev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "failed to install IRQ\n"); dev_err(&pdev->dev, "failed to install IRQ\n");
goto put_clk_gate; goto put_clk_gate;
...@@ -749,7 +735,7 @@ static int g2d_probe(struct platform_device *pdev) ...@@ -749,7 +735,7 @@ static int g2d_probe(struct platform_device *pdev)
dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev); dev->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
if (IS_ERR(dev->alloc_ctx)) { if (IS_ERR(dev->alloc_ctx)) {
ret = PTR_ERR(dev->alloc_ctx); ret = PTR_ERR(dev->alloc_ctx);
goto rel_irq; goto unprep_clk_gate;
} }
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
...@@ -797,8 +783,6 @@ static int g2d_probe(struct platform_device *pdev) ...@@ -797,8 +783,6 @@ static int g2d_probe(struct platform_device *pdev)
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
alloc_ctx_cleanup: alloc_ctx_cleanup:
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
rel_irq:
free_irq(dev->irq, dev);
unprep_clk_gate: unprep_clk_gate:
clk_unprepare(dev->gate); clk_unprepare(dev->gate);
put_clk_gate: put_clk_gate:
...@@ -807,12 +791,7 @@ static int g2d_probe(struct platform_device *pdev) ...@@ -807,12 +791,7 @@ static int g2d_probe(struct platform_device *pdev)
clk_unprepare(dev->clk); clk_unprepare(dev->clk);
put_clk: put_clk:
clk_put(dev->clk); clk_put(dev->clk);
unmap_regs:
iounmap(dev->regs);
rel_res_regs:
release_resource(dev->res_regs);
free_dev:
kfree(dev);
return ret; return ret;
} }
...@@ -825,14 +804,10 @@ static int g2d_remove(struct platform_device *pdev) ...@@ -825,14 +804,10 @@ static int g2d_remove(struct platform_device *pdev)
video_unregister_device(dev->vfd); video_unregister_device(dev->vfd);
v4l2_device_unregister(&dev->v4l2_dev); v4l2_device_unregister(&dev->v4l2_dev);
vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
free_irq(dev->irq, dev);
clk_unprepare(dev->gate); clk_unprepare(dev->gate);
clk_put(dev->gate); clk_put(dev->gate);
clk_unprepare(dev->clk); clk_unprepare(dev->clk);
clk_put(dev->clk); clk_put(dev->clk);
iounmap(dev->regs);
release_resource(dev->res_regs);
kfree(dev);
return 0; return 0;
} }
......
...@@ -23,7 +23,6 @@ struct g2d_dev { ...@@ -23,7 +23,6 @@ struct g2d_dev {
spinlock_t ctrl_lock; spinlock_t ctrl_lock;
atomic_t num_inst; atomic_t num_inst;
struct vb2_alloc_ctx *alloc_ctx; struct vb2_alloc_ctx *alloc_ctx;
struct resource *res_regs;
void __iomem *regs; void __iomem *regs;
struct clk *clk; struct clk *clk;
struct clk *gate; struct clk *gate;
......
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