video: pxa3xx-gcu: switch to devres functions

Switch to devres allocators to clean up the error unwinding paths.

Signed-off-by: Daniel Mack <zonque@gmail.com>
Acked-by: Haojian Zhuang <haojian.zhuang@gmail.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
This commit is contained in:
Daniel Mack 2014-03-05 17:12:49 +01:00 committed by Tomi Valkeinen
parent 3437b2b83f
commit a9b47c7f23

View File

@ -593,18 +593,10 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev)
struct pxa3xx_gcu_priv *priv; struct pxa3xx_gcu_priv *priv;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
priv = kzalloc(sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(struct pxa3xx_gcu_priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
for (i = 0; i < 8; i++) {
ret = pxa3xx_gcu_add_buffer(dev, priv);
if (ret) {
dev_err(dev, "failed to allocate DMA memory\n");
goto err_free_priv;
}
}
init_waitqueue_head(&priv->wait_idle); init_waitqueue_head(&priv->wait_idle);
init_waitqueue_head(&priv->wait_free); init_waitqueue_head(&priv->wait_free);
spin_lock_init(&priv->spinlock); spin_lock_init(&priv->spinlock);
@ -618,73 +610,63 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev)
priv->misc_dev.name = DRV_NAME, priv->misc_dev.name = DRV_NAME,
priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops; priv->misc_dev.fops = &pxa3xx_gcu_miscdev_fops;
/* register misc device */
ret = misc_register(&priv->misc_dev);
if (ret < 0) {
dev_err(dev, "misc_register() for minor %d failed\n",
MISCDEV_MINOR);
goto err_free_priv;
}
/* handle IO resources */ /* handle IO resources */
r = platform_get_resource(pdev, IORESOURCE_MEM, 0); r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (r == NULL) { priv->mmio_base = devm_request_and_ioremap(dev, r);
dev_err(dev, "no I/O memory resource defined\n"); if (IS_ERR(priv->mmio_base)) {
ret = -ENODEV;
goto err_misc_deregister;
}
if (!request_mem_region(r->start, resource_size(r), pdev->name)) {
dev_err(dev, "failed to request I/O memory\n");
ret = -EBUSY;
goto err_misc_deregister;
}
priv->mmio_base = ioremap_nocache(r->start, resource_size(r));
if (!priv->mmio_base) {
dev_err(dev, "failed to map I/O memory\n"); dev_err(dev, "failed to map I/O memory\n");
ret = -EBUSY; return PTR_ERR(priv->mmio_base);
goto err_free_mem_region;
}
/* allocate dma memory */
priv->shared = dma_alloc_coherent(dev, SHARED_SIZE,
&priv->shared_phys, GFP_KERNEL);
if (!priv->shared) {
dev_err(dev, "failed to allocate DMA memory\n");
ret = -ENOMEM;
goto err_free_io;
} }
/* enable the clock */ /* enable the clock */
priv->clk = clk_get(dev, NULL); priv->clk = devm_clk_get(dev, NULL);
if (IS_ERR(priv->clk)) { if (IS_ERR(priv->clk)) {
dev_err(dev, "failed to get clock\n"); dev_err(dev, "failed to get clock\n");
ret = -ENODEV; return PTR_ERR(priv->clk);
goto err_free_dma;
}
ret = clk_enable(priv->clk);
if (ret < 0) {
dev_err(dev, "failed to enable clock\n");
goto err_put_clk;
} }
/* request the IRQ */ /* request the IRQ */
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq < 0) { if (irq < 0) {
dev_err(dev, "no IRQ defined\n"); dev_err(dev, "no IRQ defined\n");
ret = -ENODEV; return -ENODEV;
goto err_put_clk;
} }
ret = request_irq(irq, pxa3xx_gcu_handle_irq, ret = devm_request_irq(dev, irq, pxa3xx_gcu_handle_irq,
0, DRV_NAME, priv); 0, DRV_NAME, priv);
if (ret) { if (ret < 0) {
dev_err(dev, "request_irq failed\n"); dev_err(dev, "request_irq failed\n");
ret = -EBUSY; return ret;
goto err_put_clk; }
/* allocate dma memory */
priv->shared = dma_alloc_coherent(dev, SHARED_SIZE,
&priv->shared_phys, GFP_KERNEL);
if (!priv->shared) {
dev_err(dev, "failed to allocate DMA memory\n");
return -ENOMEM;
}
/* register misc device */
ret = misc_register(&priv->misc_dev);
if (ret < 0) {
dev_err(dev, "misc_register() for minor %d failed\n",
MISCDEV_MINOR);
goto err_free_dma;
}
ret = clk_enable(priv->clk);
if (ret < 0) {
dev_err(dev, "failed to enable clock\n");
goto err_misc_deregister;
}
for (i = 0; i < 8; i++) {
ret = pxa3xx_gcu_add_buffer(dev, priv);
if (ret) {
dev_err(dev, "failed to allocate DMA memory\n");
goto err_disable_clk;
}
} }
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
@ -697,45 +679,28 @@ static int pxa3xx_gcu_probe(struct platform_device *pdev)
SHARED_SIZE, irq); SHARED_SIZE, irq);
return 0; return 0;
err_put_clk:
clk_disable(priv->clk);
clk_put(priv->clk);
err_free_dma: err_free_dma:
dma_free_coherent(dev, SHARED_SIZE, dma_free_coherent(dev, SHARED_SIZE,
priv->shared, priv->shared_phys); priv->shared, priv->shared_phys);
err_free_io:
iounmap(priv->mmio_base);
err_free_mem_region:
release_mem_region(r->start, resource_size(r));
err_misc_deregister: err_misc_deregister:
misc_deregister(&priv->misc_dev); misc_deregister(&priv->misc_dev);
err_free_priv: err_disable_clk:
pxa3xx_gcu_free_buffers(dev, priv); clk_disable(priv->clk);
kfree(priv);
return ret; return ret;
} }
static int pxa3xx_gcu_remove(struct platform_device *pdev) static int pxa3xx_gcu_remove(struct platform_device *pdev)
{ {
struct pxa3xx_gcu_priv *priv = platform_get_drvdata(pdev); struct pxa3xx_gcu_priv *priv = platform_get_drvdata(pdev);
struct resource *r = priv->resource_mem;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
pxa3xx_gcu_wait_idle(priv); pxa3xx_gcu_wait_idle(priv);
misc_deregister(&priv->misc_dev); misc_deregister(&priv->misc_dev);
dma_free_coherent(dev, SHARED_SIZE, dma_free_coherent(dev, SHARED_SIZE, priv->shared, priv->shared_phys);
priv->shared, priv->shared_phys);
iounmap(priv->mmio_base);
release_mem_region(r->start, resource_size(r));
clk_disable(priv->clk);
pxa3xx_gcu_free_buffers(dev, priv); pxa3xx_gcu_free_buffers(dev, priv);
kfree(priv);
return 0; return 0;
} }