dma: coh901318: use devm allocation
Allocate memory, region, remap and irq for device state using devm_* helpers to simplify memory accounting. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
This commit is contained in:
parent
9102d8715e
commit
f7ceb362c4
@ -1438,34 +1438,32 @@ static int __init coh901318_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||||
if (!io)
|
if (!io)
|
||||||
goto err_get_resource;
|
return -ENODEV;
|
||||||
|
|
||||||
/* Map DMA controller registers to virtual memory */
|
/* Map DMA controller registers to virtual memory */
|
||||||
if (request_mem_region(io->start,
|
if (devm_request_mem_region(&pdev->dev,
|
||||||
resource_size(io),
|
io->start,
|
||||||
pdev->dev.driver->name) == NULL) {
|
resource_size(io),
|
||||||
err = -EBUSY;
|
pdev->dev.driver->name) == NULL)
|
||||||
goto err_request_mem;
|
return -ENOMEM;
|
||||||
}
|
|
||||||
|
|
||||||
pdata = pdev->dev.platform_data;
|
pdata = pdev->dev.platform_data;
|
||||||
if (!pdata)
|
if (!pdata)
|
||||||
goto err_no_platformdata;
|
return -ENODEV;
|
||||||
|
|
||||||
base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) +
|
base = devm_kzalloc(&pdev->dev,
|
||||||
pdata->max_channels *
|
ALIGN(sizeof(struct coh901318_base), 4) +
|
||||||
sizeof(struct coh901318_chan),
|
pdata->max_channels *
|
||||||
GFP_KERNEL);
|
sizeof(struct coh901318_chan),
|
||||||
|
GFP_KERNEL);
|
||||||
if (!base)
|
if (!base)
|
||||||
goto err_alloc_coh_dma_channels;
|
return -ENOMEM;
|
||||||
|
|
||||||
base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
|
base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
|
||||||
|
|
||||||
base->virtbase = ioremap(io->start, resource_size(io));
|
base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io));
|
||||||
if (!base->virtbase) {
|
if (!base->virtbase)
|
||||||
err = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto err_no_ioremap;
|
|
||||||
}
|
|
||||||
|
|
||||||
base->dev = &pdev->dev;
|
base->dev = &pdev->dev;
|
||||||
base->platform = pdata;
|
base->platform = pdata;
|
||||||
@ -1474,25 +1472,20 @@ static int __init coh901318_probe(struct platform_device *pdev)
|
|||||||
|
|
||||||
COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
|
COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
|
||||||
|
|
||||||
platform_set_drvdata(pdev, base);
|
|
||||||
|
|
||||||
irq = platform_get_irq(pdev, 0);
|
irq = platform_get_irq(pdev, 0);
|
||||||
if (irq < 0)
|
if (irq < 0)
|
||||||
goto err_no_irq;
|
return irq;
|
||||||
|
|
||||||
err = request_irq(irq, dma_irq_handler, IRQF_DISABLED,
|
err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED,
|
||||||
"coh901318", base);
|
"coh901318", base);
|
||||||
if (err) {
|
if (err)
|
||||||
dev_crit(&pdev->dev,
|
return err;
|
||||||
"Cannot allocate IRQ for DMA controller!\n");
|
|
||||||
goto err_request_irq;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = coh901318_pool_create(&base->pool, &pdev->dev,
|
err = coh901318_pool_create(&base->pool, &pdev->dev,
|
||||||
sizeof(struct coh901318_lli),
|
sizeof(struct coh901318_lli),
|
||||||
32);
|
32);
|
||||||
if (err)
|
if (err)
|
||||||
goto err_pool_create;
|
return err;
|
||||||
|
|
||||||
/* init channels for device transfers */
|
/* init channels for device transfers */
|
||||||
coh901318_base_init(&base->dma_slave, base->platform->chans_slave,
|
coh901318_base_init(&base->dma_slave, base->platform->chans_slave,
|
||||||
@ -1538,6 +1531,7 @@ static int __init coh901318_probe(struct platform_device *pdev)
|
|||||||
if (err)
|
if (err)
|
||||||
goto err_register_memcpy;
|
goto err_register_memcpy;
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, base);
|
||||||
dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
|
dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
|
||||||
(u32) base->virtbase);
|
(u32) base->virtbase);
|
||||||
|
|
||||||
@ -1547,19 +1541,6 @@ static int __init coh901318_probe(struct platform_device *pdev)
|
|||||||
dma_async_device_unregister(&base->dma_slave);
|
dma_async_device_unregister(&base->dma_slave);
|
||||||
err_register_slave:
|
err_register_slave:
|
||||||
coh901318_pool_destroy(&base->pool);
|
coh901318_pool_destroy(&base->pool);
|
||||||
err_pool_create:
|
|
||||||
free_irq(platform_get_irq(pdev, 0), base);
|
|
||||||
err_request_irq:
|
|
||||||
err_no_irq:
|
|
||||||
iounmap(base->virtbase);
|
|
||||||
err_no_ioremap:
|
|
||||||
kfree(base);
|
|
||||||
err_alloc_coh_dma_channels:
|
|
||||||
err_no_platformdata:
|
|
||||||
release_mem_region(pdev->resource->start,
|
|
||||||
resource_size(pdev->resource));
|
|
||||||
err_request_mem:
|
|
||||||
err_get_resource:
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1570,11 +1551,6 @@ static int __exit coh901318_remove(struct platform_device *pdev)
|
|||||||
dma_async_device_unregister(&base->dma_memcpy);
|
dma_async_device_unregister(&base->dma_memcpy);
|
||||||
dma_async_device_unregister(&base->dma_slave);
|
dma_async_device_unregister(&base->dma_slave);
|
||||||
coh901318_pool_destroy(&base->pool);
|
coh901318_pool_destroy(&base->pool);
|
||||||
free_irq(platform_get_irq(pdev, 0), base);
|
|
||||||
iounmap(base->virtbase);
|
|
||||||
kfree(base);
|
|
||||||
release_mem_region(pdev->resource->start,
|
|
||||||
resource_size(pdev->resource));
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user