Commit f7ceb362c4d2f4e613982148ddb143ad6a205485
Committed by
Vinod Koul
1 parent
9102d8715e
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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>
Showing 1 changed file with 24 additions and 48 deletions Side-by-side Diff
drivers/dma/coh901318.c
... | ... | @@ -1438,34 +1438,32 @@ |
1438 | 1438 | |
1439 | 1439 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
1440 | 1440 | if (!io) |
1441 | - goto err_get_resource; | |
1441 | + return -ENODEV; | |
1442 | 1442 | |
1443 | 1443 | /* Map DMA controller registers to virtual memory */ |
1444 | - if (request_mem_region(io->start, | |
1445 | - resource_size(io), | |
1446 | - pdev->dev.driver->name) == NULL) { | |
1447 | - err = -EBUSY; | |
1448 | - goto err_request_mem; | |
1449 | - } | |
1444 | + if (devm_request_mem_region(&pdev->dev, | |
1445 | + io->start, | |
1446 | + resource_size(io), | |
1447 | + pdev->dev.driver->name) == NULL) | |
1448 | + return -ENOMEM; | |
1450 | 1449 | |
1451 | 1450 | pdata = pdev->dev.platform_data; |
1452 | 1451 | if (!pdata) |
1453 | - goto err_no_platformdata; | |
1452 | + return -ENODEV; | |
1454 | 1453 | |
1455 | - base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) + | |
1456 | - pdata->max_channels * | |
1457 | - sizeof(struct coh901318_chan), | |
1458 | - GFP_KERNEL); | |
1454 | + base = devm_kzalloc(&pdev->dev, | |
1455 | + ALIGN(sizeof(struct coh901318_base), 4) + | |
1456 | + pdata->max_channels * | |
1457 | + sizeof(struct coh901318_chan), | |
1458 | + GFP_KERNEL); | |
1459 | 1459 | if (!base) |
1460 | - goto err_alloc_coh_dma_channels; | |
1460 | + return -ENOMEM; | |
1461 | 1461 | |
1462 | 1462 | base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4); |
1463 | 1463 | |
1464 | - base->virtbase = ioremap(io->start, resource_size(io)); | |
1465 | - if (!base->virtbase) { | |
1466 | - err = -ENOMEM; | |
1467 | - goto err_no_ioremap; | |
1468 | - } | |
1464 | + base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io)); | |
1465 | + if (!base->virtbase) | |
1466 | + return -ENOMEM; | |
1469 | 1467 | |
1470 | 1468 | base->dev = &pdev->dev; |
1471 | 1469 | base->platform = pdata; |
1472 | 1470 | |
1473 | 1471 | |
1474 | 1472 | |
... | ... | @@ -1474,25 +1472,20 @@ |
1474 | 1472 | |
1475 | 1473 | COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base); |
1476 | 1474 | |
1477 | - platform_set_drvdata(pdev, base); | |
1478 | - | |
1479 | 1475 | irq = platform_get_irq(pdev, 0); |
1480 | 1476 | if (irq < 0) |
1481 | - goto err_no_irq; | |
1477 | + return irq; | |
1482 | 1478 | |
1483 | - err = request_irq(irq, dma_irq_handler, IRQF_DISABLED, | |
1484 | - "coh901318", base); | |
1485 | - if (err) { | |
1486 | - dev_crit(&pdev->dev, | |
1487 | - "Cannot allocate IRQ for DMA controller!\n"); | |
1488 | - goto err_request_irq; | |
1489 | - } | |
1479 | + err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED, | |
1480 | + "coh901318", base); | |
1481 | + if (err) | |
1482 | + return err; | |
1490 | 1483 | |
1491 | 1484 | err = coh901318_pool_create(&base->pool, &pdev->dev, |
1492 | 1485 | sizeof(struct coh901318_lli), |
1493 | 1486 | 32); |
1494 | 1487 | if (err) |
1495 | - goto err_pool_create; | |
1488 | + return err; | |
1496 | 1489 | |
1497 | 1490 | /* init channels for device transfers */ |
1498 | 1491 | coh901318_base_init(&base->dma_slave, base->platform->chans_slave, |
... | ... | @@ -1538,6 +1531,7 @@ |
1538 | 1531 | if (err) |
1539 | 1532 | goto err_register_memcpy; |
1540 | 1533 | |
1534 | + platform_set_drvdata(pdev, base); | |
1541 | 1535 | dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n", |
1542 | 1536 | (u32) base->virtbase); |
1543 | 1537 | |
... | ... | @@ -1547,19 +1541,6 @@ |
1547 | 1541 | dma_async_device_unregister(&base->dma_slave); |
1548 | 1542 | err_register_slave: |
1549 | 1543 | coh901318_pool_destroy(&base->pool); |
1550 | - err_pool_create: | |
1551 | - free_irq(platform_get_irq(pdev, 0), base); | |
1552 | - err_request_irq: | |
1553 | - err_no_irq: | |
1554 | - iounmap(base->virtbase); | |
1555 | - err_no_ioremap: | |
1556 | - kfree(base); | |
1557 | - err_alloc_coh_dma_channels: | |
1558 | - err_no_platformdata: | |
1559 | - release_mem_region(pdev->resource->start, | |
1560 | - resource_size(pdev->resource)); | |
1561 | - err_request_mem: | |
1562 | - err_get_resource: | |
1563 | 1544 | return err; |
1564 | 1545 | } |
1565 | 1546 | |
... | ... | @@ -1570,11 +1551,6 @@ |
1570 | 1551 | dma_async_device_unregister(&base->dma_memcpy); |
1571 | 1552 | dma_async_device_unregister(&base->dma_slave); |
1572 | 1553 | coh901318_pool_destroy(&base->pool); |
1573 | - free_irq(platform_get_irq(pdev, 0), base); | |
1574 | - iounmap(base->virtbase); | |
1575 | - kfree(base); | |
1576 | - release_mem_region(pdev->resource->start, | |
1577 | - resource_size(pdev->resource)); | |
1578 | 1554 | return 0; |
1579 | 1555 | } |
1580 | 1556 |