Skip to content

Commit 3c62fd3

Browse files
tititiou36vinodkoul
authored andcommitted
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: fa5d823 ("dmaengine: ptdma: Initial driver for the AMD PTDMA") Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Acked-by: Sanjay R Mehta <sanju.mehta@amd.com> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/41a963a35173f89c874f5c44df5530dc09fea8da.1644044244.git.christophe.jaillet@wanadoo.fr Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent e783362 commit 3c62fd3

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/dma/ptdma/ptdma-dev.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int pt_core_init(struct pt_device *pt)
207207
if (!cmd_q->qbase) {
208208
dev_err(dev, "unable to allocate command queue\n");
209209
ret = -ENOMEM;
210-
goto e_dma_alloc;
210+
goto e_destroy_pool;
211211
}
212212

213213
cmd_q->qidx = 0;
@@ -229,8 +229,10 @@ int pt_core_init(struct pt_device *pt)
229229

230230
/* Request an irq */
231231
ret = request_irq(pt->pt_irq, pt_core_irq_handler, 0, dev_name(pt->dev), pt);
232-
if (ret)
233-
goto e_pool;
232+
if (ret) {
233+
dev_err(dev, "unable to allocate an IRQ\n");
234+
goto e_free_dma;
235+
}
234236

235237
/* Update the device registers with queue information. */
236238
cmd_q->qcontrol &= ~CMD_Q_SIZE;
@@ -250,21 +252,20 @@ int pt_core_init(struct pt_device *pt)
250252
/* Register the DMA engine support */
251253
ret = pt_dmaengine_register(pt);
252254
if (ret)
253-
goto e_dmaengine;
255+
goto e_free_irq;
254256

255257
/* Set up debugfs entries */
256258
ptdma_debugfs_setup(pt);
257259

258260
return 0;
259261

260-
e_dmaengine:
262+
e_free_irq:
261263
free_irq(pt->pt_irq, pt);
262264

263-
e_dma_alloc:
265+
e_free_dma:
264266
dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma);
265267

266-
e_pool:
267-
dev_err(dev, "unable to allocate an IRQ\n");
268+
e_destroy_pool:
268269
dma_pool_destroy(pt->cmd_q.dma_pool);
269270

270271
return ret;

0 commit comments

Comments
 (0)