Commit 3c62fd34 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Vinod Koul

dmaengine: ptdma: Fix the error handling path in pt_core_init()

In order to free resources correctly in the error handling path of
pt_core_init(), 2 goto's have to be switched. Otherwise, some resources
will leak and we will try to release things that have not been allocated
yet.

Also move a dev_err() to a place where it is more meaningful.

Fixes: fa5d823b ("dmaengine: ptdma: Initial driver for the AMD PTDMA")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: default avatarSanjay R Mehta <sanju.mehta@amd.com>
Reviewed-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Link: https://lore.kernel.org/r/41a963a35173f89c874f5c44df5530dc09fea8da.1644044244.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent e783362e
...@@ -207,7 +207,7 @@ int pt_core_init(struct pt_device *pt) ...@@ -207,7 +207,7 @@ int pt_core_init(struct pt_device *pt)
if (!cmd_q->qbase) { if (!cmd_q->qbase) {
dev_err(dev, "unable to allocate command queue\n"); dev_err(dev, "unable to allocate command queue\n");
ret = -ENOMEM; ret = -ENOMEM;
goto e_dma_alloc; goto e_destroy_pool;
} }
cmd_q->qidx = 0; cmd_q->qidx = 0;
...@@ -229,8 +229,10 @@ int pt_core_init(struct pt_device *pt) ...@@ -229,8 +229,10 @@ int pt_core_init(struct pt_device *pt)
/* Request an irq */ /* Request an irq */
ret = request_irq(pt->pt_irq, pt_core_irq_handler, 0, dev_name(pt->dev), pt); ret = request_irq(pt->pt_irq, pt_core_irq_handler, 0, dev_name(pt->dev), pt);
if (ret) if (ret) {
goto e_pool; dev_err(dev, "unable to allocate an IRQ\n");
goto e_free_dma;
}
/* Update the device registers with queue information. */ /* Update the device registers with queue information. */
cmd_q->qcontrol &= ~CMD_Q_SIZE; cmd_q->qcontrol &= ~CMD_Q_SIZE;
...@@ -250,21 +252,20 @@ int pt_core_init(struct pt_device *pt) ...@@ -250,21 +252,20 @@ int pt_core_init(struct pt_device *pt)
/* Register the DMA engine support */ /* Register the DMA engine support */
ret = pt_dmaengine_register(pt); ret = pt_dmaengine_register(pt);
if (ret) if (ret)
goto e_dmaengine; goto e_free_irq;
/* Set up debugfs entries */ /* Set up debugfs entries */
ptdma_debugfs_setup(pt); ptdma_debugfs_setup(pt);
return 0; return 0;
e_dmaengine: e_free_irq:
free_irq(pt->pt_irq, pt); free_irq(pt->pt_irq, pt);
e_dma_alloc: e_free_dma:
dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma); dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma);
e_pool: e_destroy_pool:
dev_err(dev, "unable to allocate an IRQ\n");
dma_pool_destroy(pt->cmd_q.dma_pool); dma_pool_destroy(pt->cmd_q.dma_pool);
return ret; return ret;
......
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