From: "Lad, Prabhakar" <[email protected]>
Use devm_ioremap_resource instead of reques_mem_region()/ioremap(),
devm_request_irq() instead of request_irq() and kzalloc() calls to
devm_kzalloc().
This ensures more consistent error values and simplifies error paths.
Signed-off-by: Lad, Prabhakar <[email protected]>
---
This patch is boot tested on DA850 EVM.
Changes for v2:
1: Fixed review comments pointed by Sergei.
2: Rebased the patch on http://www.spinics.net/lists/arm-kernel/msg252087.html
arch/arm/common/edma.c | 64 ++++++++++++++----------------------------------
1 file changed, 19 insertions(+), 45 deletions(-)
diff --git a/arch/arm/common/edma.c b/arch/arm/common/edma.c
index a1db6cd..565ddda 100644
--- a/arch/arm/common/edma.c
+++ b/arch/arm/common/edma.c
@@ -1382,7 +1382,6 @@ static int __init edma_probe(struct platform_device *pdev)
int irq[EDMA_MAX_CC] = {0, 0};
int err_irq[EDMA_MAX_CC] = {0, 0};
struct resource *r[EDMA_MAX_CC] = {NULL};
- resource_size_t len[EDMA_MAX_CC];
char res_name[10];
char irq_name[10];
@@ -1402,26 +1401,14 @@ static int __init edma_probe(struct platform_device *pdev)
found = 1;
}
- len[j] = resource_size(r[j]);
+ edmacc_regs_base[j] = devm_ioremap_resource(&pdev->dev, r[j]);
+ if (IS_ERR(edmacc_regs_base[j]))
+ return PTR_ERR(edmacc_regs_base[j]);
- r[j] = request_mem_region(r[j]->start, len[j],
- dev_name(&pdev->dev));
- if (!r[j]) {
- status = -EBUSY;
- goto fail1;
- }
-
- edmacc_regs_base[j] = ioremap(r[j]->start, len[j]);
- if (!edmacc_regs_base[j]) {
- status = -EBUSY;
- goto fail1;
- }
-
- edma_cc[j] = kzalloc(sizeof(struct edma), GFP_KERNEL);
- if (!edma_cc[j]) {
- status = -ENOMEM;
- goto fail1;
- }
+ edma_cc[j] = devm_kzalloc(&pdev->dev, sizeof(struct edma),
+ GFP_KERNEL);
+ if (!edma_cc[j])
+ return -ENOMEM;
edma_cc[j]->num_channels = min_t(unsigned, info[j]->n_channel,
EDMA_MAX_DMACH);
@@ -1471,23 +1458,27 @@ static int __init edma_probe(struct platform_device *pdev)
sprintf(irq_name, "edma%d", j);
irq[j] = platform_get_irq_byname(pdev, irq_name);
edma_cc[j]->irq_res_start = irq[j];
- status = request_irq(irq[j], dma_irq_handler, 0, "edma",
- &pdev->dev);
+ status = devm_request_irq(&pdev->dev, irq[j],
+ dma_irq_handler, 0, "edma",
+ &pdev->dev);
if (status < 0) {
- dev_dbg(&pdev->dev, "request_irq %d failed --> %d\n",
+ dev_dbg(&pdev->dev,
+ "devm_request_irq %d failed --> %d\n",
irq[j], status);
- goto fail;
+ return status;
}
sprintf(irq_name, "edma%d_err", j);
err_irq[j] = platform_get_irq_byname(pdev, irq_name);
edma_cc[j]->irq_res_end = err_irq[j];
- status = request_irq(err_irq[j], dma_ccerr_handler, 0,
- "edma_error", &pdev->dev);
+ status = devm_request_irq(&pdev->dev, err_irq[j],
+ dma_ccerr_handler, 0,
+ "edma_error", &pdev->dev);
if (status < 0) {
- dev_dbg(&pdev->dev, "request_irq %d failed --> %d\n",
+ dev_dbg(&pdev->dev,
+ "devm_request_irq %d failed --> %d\n",
err_irq[j], status);
- goto fail;
+ return status;
}
for (i = 0; i < edma_cc[j]->num_channels; i++)
@@ -1522,23 +1513,6 @@ static int __init edma_probe(struct platform_device *pdev)
}
return 0;
-
-fail:
- for (i = 0; i < EDMA_MAX_CC; i++) {
- if (err_irq[i])
- free_irq(err_irq[i], &pdev->dev);
- if (irq[i])
- free_irq(irq[i], &pdev->dev);
- }
-fail1:
- for (i = 0; i < EDMA_MAX_CC; i++) {
- if (r[i])
- release_mem_region(r[i]->start, len[i]);
- if (edmacc_regs_base[i])
- iounmap(edmacc_regs_base[i]);
- kfree(edma_cc[i]);
- }
- return status;
}
--
1.7.9.5
On 6/17/2013 8:27 PM, Prabhakar Lad wrote:
> From: "Lad, Prabhakar" <[email protected]>
>
> Use devm_ioremap_resource instead of reques_mem_region()/ioremap(),
> devm_request_irq() instead of request_irq() and kzalloc() calls to
> devm_kzalloc().
>
> This ensures more consistent error values and simplifies error paths.
>
> Signed-off-by: Lad, Prabhakar <[email protected]>
Nice clean-up. The patch did not build since <linux/err.h> was not
included. I fixed it locally and applied to v3.11/soc-2 branch of my tree.
Thanks,
Sekhar
Hi Sekhar,
On Tue, Jun 18, 2013 at 2:05 PM, Sekhar Nori <[email protected]> wrote:
> On 6/17/2013 8:27 PM, Prabhakar Lad wrote:
>> From: "Lad, Prabhakar" <[email protected]>
>>
>> Use devm_ioremap_resource instead of reques_mem_region()/ioremap(),
>> devm_request_irq() instead of request_irq() and kzalloc() calls to
>> devm_kzalloc().
>>
>> This ensures more consistent error values and simplifies error paths.
>>
>> Signed-off-by: Lad, Prabhakar <[email protected]>
>
> Nice clean-up. The patch did not build since <linux/err.h> was not
> included. I fixed it locally and applied to v3.11/soc-2 branch of my tree.
>
Thanks for fixing it.
Regards,
--Prabhakar Lad