Commit baca66f7 authored by Alexander Popov's avatar Alexander Popov Committed by Vinod Koul

dma: mpc512x: fix freeing resources in mpc_dma_probe() and mpc_dma_remove()

Fix mpc_dma_probe() error path and mpc_dma_remove(): manually free IRQs and
dispose IRQ mappings before devm_* takes care of other resources.
Moreover replace devm_request_irq() with request_irq() since there is no need
to use it because the original code always frees IRQ manually with
devm_free_irq(). Replace devm_free_irq() with free_irq() accordingly.
Signed-off-by: default avatarAlexander Popov <a13xp0p0v88@gmail.com>
Signed-off-by: default avatarVinod Koul <vinod.koul@intel.com>
parent 62057d33
...@@ -657,13 +657,15 @@ static int mpc_dma_probe(struct platform_device *op) ...@@ -657,13 +657,15 @@ static int mpc_dma_probe(struct platform_device *op)
mdma = devm_kzalloc(dev, sizeof(struct mpc_dma), GFP_KERNEL); mdma = devm_kzalloc(dev, sizeof(struct mpc_dma), GFP_KERNEL);
if (!mdma) { if (!mdma) {
dev_err(dev, "Memory exhausted!\n"); dev_err(dev, "Memory exhausted!\n");
return -ENOMEM; retval = -ENOMEM;
goto err;
} }
mdma->irq = irq_of_parse_and_map(dn, 0); mdma->irq = irq_of_parse_and_map(dn, 0);
if (mdma->irq == NO_IRQ) { if (mdma->irq == NO_IRQ) {
dev_err(dev, "Error mapping IRQ!\n"); dev_err(dev, "Error mapping IRQ!\n");
return -EINVAL; retval = -EINVAL;
goto err;
} }
if (of_device_is_compatible(dn, "fsl,mpc8308-dma")) { if (of_device_is_compatible(dn, "fsl,mpc8308-dma")) {
...@@ -671,14 +673,15 @@ static int mpc_dma_probe(struct platform_device *op) ...@@ -671,14 +673,15 @@ static int mpc_dma_probe(struct platform_device *op)
mdma->irq2 = irq_of_parse_and_map(dn, 1); mdma->irq2 = irq_of_parse_and_map(dn, 1);
if (mdma->irq2 == NO_IRQ) { if (mdma->irq2 == NO_IRQ) {
dev_err(dev, "Error mapping IRQ!\n"); dev_err(dev, "Error mapping IRQ!\n");
return -EINVAL; retval = -EINVAL;
goto err_dispose1;
} }
} }
retval = of_address_to_resource(dn, 0, &res); retval = of_address_to_resource(dn, 0, &res);
if (retval) { if (retval) {
dev_err(dev, "Error parsing memory region!\n"); dev_err(dev, "Error parsing memory region!\n");
return retval; goto err_dispose2;
} }
regs_start = res.start; regs_start = res.start;
...@@ -686,31 +689,34 @@ static int mpc_dma_probe(struct platform_device *op) ...@@ -686,31 +689,34 @@ static int mpc_dma_probe(struct platform_device *op)
if (!devm_request_mem_region(dev, regs_start, regs_size, DRV_NAME)) { if (!devm_request_mem_region(dev, regs_start, regs_size, DRV_NAME)) {
dev_err(dev, "Error requesting memory region!\n"); dev_err(dev, "Error requesting memory region!\n");
return -EBUSY; retval = -EBUSY;
goto err_dispose2;
} }
mdma->regs = devm_ioremap(dev, regs_start, regs_size); mdma->regs = devm_ioremap(dev, regs_start, regs_size);
if (!mdma->regs) { if (!mdma->regs) {
dev_err(dev, "Error mapping memory region!\n"); dev_err(dev, "Error mapping memory region!\n");
return -ENOMEM; retval = -ENOMEM;
goto err_dispose2;
} }
mdma->tcd = (struct mpc_dma_tcd *)((u8 *)(mdma->regs) mdma->tcd = (struct mpc_dma_tcd *)((u8 *)(mdma->regs)
+ MPC_DMA_TCD_OFFSET); + MPC_DMA_TCD_OFFSET);
retval = devm_request_irq(dev, mdma->irq, &mpc_dma_irq, 0, DRV_NAME, retval = request_irq(mdma->irq, &mpc_dma_irq, 0, DRV_NAME, mdma);
mdma);
if (retval) { if (retval) {
dev_err(dev, "Error requesting IRQ!\n"); dev_err(dev, "Error requesting IRQ!\n");
return -EINVAL; retval = -EINVAL;
goto err_dispose2;
} }
if (mdma->is_mpc8308) { if (mdma->is_mpc8308) {
retval = devm_request_irq(dev, mdma->irq2, &mpc_dma_irq, 0, retval = request_irq(mdma->irq2, &mpc_dma_irq, 0,
DRV_NAME, mdma); DRV_NAME, mdma);
if (retval) { if (retval) {
dev_err(dev, "Error requesting IRQ2!\n"); dev_err(dev, "Error requesting IRQ2!\n");
return -EINVAL; retval = -EINVAL;
goto err_free1;
} }
} }
...@@ -793,12 +799,23 @@ static int mpc_dma_probe(struct platform_device *op) ...@@ -793,12 +799,23 @@ static int mpc_dma_probe(struct platform_device *op)
/* Register DMA engine */ /* Register DMA engine */
dev_set_drvdata(dev, mdma); dev_set_drvdata(dev, mdma);
retval = dma_async_device_register(dma); retval = dma_async_device_register(dma);
if (retval) { if (retval)
devm_free_irq(dev, mdma->irq, mdma); goto err_free2;
irq_dispose_mapping(mdma->irq);
}
return retval; return retval;
err_free2:
if (mdma->is_mpc8308)
free_irq(mdma->irq2, mdma);
err_free1:
free_irq(mdma->irq, mdma);
err_dispose2:
if (mdma->is_mpc8308)
irq_dispose_mapping(mdma->irq2);
err_dispose1:
irq_dispose_mapping(mdma->irq);
err:
return retval;
} }
static int mpc_dma_remove(struct platform_device *op) static int mpc_dma_remove(struct platform_device *op)
...@@ -807,7 +824,11 @@ static int mpc_dma_remove(struct platform_device *op) ...@@ -807,7 +824,11 @@ static int mpc_dma_remove(struct platform_device *op)
struct mpc_dma *mdma = dev_get_drvdata(dev); struct mpc_dma *mdma = dev_get_drvdata(dev);
dma_async_device_unregister(&mdma->dma); dma_async_device_unregister(&mdma->dma);
devm_free_irq(dev, mdma->irq, mdma); if (mdma->is_mpc8308) {
free_irq(mdma->irq2, mdma);
irq_dispose_mapping(mdma->irq2);
}
free_irq(mdma->irq, mdma);
irq_dispose_mapping(mdma->irq); irq_dispose_mapping(mdma->irq);
return 0; return 0;
......
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