diff mbox series

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

Message ID 41a963a35173f89c874f5c44df5530dc09fea8da.1644044244.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Commit 3c62fd3406e0b2277c76a6984d3979c7f3f1d129
Headers show
Series [v2] dmaengine: ptdma: Fix the error handling path in pt_core_init() | expand

Commit Message

Christophe JAILLET Feb. 5, 2022, 6:58 a.m. UTC
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: fa5d823b16a9 ("dmaengine: ptdma: Initial driver for the AMD PTDMA")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
v2: update label names
    move dev_err(dev, "unable to allocate an IRQ\n");
---
 drivers/dma/ptdma/ptdma-dev.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Dan Carpenter Feb. 7, 2022, 4:51 p.m. UTC | #1
On Sat, Feb 05, 2022 at 07:58:44AM +0100, Christophe JAILLET wrote:
> 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: fa5d823b16a9 ("dmaengine: ptdma: Initial driver for the AMD PTDMA")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> v2: update label names
>     move dev_err(dev, "unable to allocate an IRQ\n");

Awesome.  Thanks!

Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

regards,
dan carpenter
Sanjay R Mehta Feb. 8, 2022, 4:24 a.m. UTC | #2
On 2/7/2022 10:21 PM, Dan Carpenter wrote:
> On Sat, Feb 05, 2022 at 07:58:44AM +0100, Christophe JAILLET wrote:
>> 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: fa5d823b16a9 ("dmaengine: ptdma: Initial driver for the AMD PTDMA")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> v2: update label names
>>     move dev_err(dev, "unable to allocate an IRQ\n");
> 
> Awesome.  Thanks!
> 
> Reviewed-by: Dan Carpenter <dan.carpenter@oracle.com>

Thank you!

Acked-by: Sanjay R Mehta <sanju.mehta@amd.com>
> 
> regards,
> dan carpenter
>
Vinod Koul Feb. 15, 2022, 5:18 a.m. UTC | #3
On 05-02-22, 07:58, Christophe JAILLET wrote:
> 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.

Applied, thanks
diff mbox series

Patch

diff --git a/drivers/dma/ptdma/ptdma-dev.c b/drivers/dma/ptdma/ptdma-dev.c
index 8a6bf291a73f..daafea5bc35d 100644
--- a/drivers/dma/ptdma/ptdma-dev.c
+++ b/drivers/dma/ptdma/ptdma-dev.c
@@ -207,7 +207,7 @@  int pt_core_init(struct pt_device *pt)
 	if (!cmd_q->qbase) {
 		dev_err(dev, "unable to allocate command queue\n");
 		ret = -ENOMEM;
-		goto e_dma_alloc;
+		goto e_destroy_pool;
 	}
 
 	cmd_q->qidx = 0;
@@ -229,8 +229,10 @@  int pt_core_init(struct pt_device *pt)
 
 	/* Request an irq */
 	ret = request_irq(pt->pt_irq, pt_core_irq_handler, 0, dev_name(pt->dev), pt);
-	if (ret)
-		goto e_pool;
+	if (ret) {
+		dev_err(dev, "unable to allocate an IRQ\n");
+		goto e_free_dma;
+	}
 
 	/* Update the device registers with queue information. */
 	cmd_q->qcontrol &= ~CMD_Q_SIZE;
@@ -250,21 +252,20 @@  int pt_core_init(struct pt_device *pt)
 	/* Register the DMA engine support */
 	ret = pt_dmaengine_register(pt);
 	if (ret)
-		goto e_dmaengine;
+		goto e_free_irq;
 
 	/* Set up debugfs entries */
 	ptdma_debugfs_setup(pt);
 
 	return 0;
 
-e_dmaengine:
+e_free_irq:
 	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);
 
-e_pool:
-	dev_err(dev, "unable to allocate an IRQ\n");
+e_destroy_pool:
 	dma_pool_destroy(pt->cmd_q.dma_pool);
 
 	return ret;