mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths
@ 2024-01-07 10:02 Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA Christophe JAILLET
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-01-07 10:02 UTC (permalink / raw)
  To: vkoul, jiaheng.fan, peng.ma, wen.he_1
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

The first 2 patches are bug fixes related to missing dma_free_coherent() either
in the remove function or in the error handling path of the probe.

They are compile tested only. So review with care.

The 3rd patch is only a clean up.

Christophe JAILLET (3):
  dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA
  dmaengine: fsl-qdma: Fix a memory leak related to the queue command
    DMA
  dmaengine: fsl-qdma: Remove a useless devm_kfree()

 drivers/dma/fsl-qdma.c | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA
  2024-01-07 10:02 [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Christophe JAILLET
@ 2024-01-07 10:02 ` Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 2/3] dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA Christophe JAILLET
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-01-07 10:02 UTC (permalink / raw)
  To: vkoul, jiaheng.fan, peng.ma, wen.he_1
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

This dma_alloc_coherent() is undone in the remove function, but not in the
error handling path of fsl_qdma_probe().

Switch to the managed version to fix the issue in the probe and simplify
the remove function.

Fixes: b092529e0aa0 ("dmaengine: fsl-qdma: Add qDMA controller driver for Layerscape SoCs")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/fsl-qdma.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/drivers/dma/fsl-qdma.c b/drivers/dma/fsl-qdma.c
index 47cb28468049..38409e06040a 100644
--- a/drivers/dma/fsl-qdma.c
+++ b/drivers/dma/fsl-qdma.c
@@ -563,11 +563,11 @@ static struct fsl_qdma_queue
 	/*
 	 * Buffer for queue command
 	 */
-	status_head->cq = dma_alloc_coherent(&pdev->dev,
-					     sizeof(struct fsl_qdma_format) *
-					     status_size,
-					     &status_head->bus_addr,
-					     GFP_KERNEL);
+	status_head->cq = dmam_alloc_coherent(&pdev->dev,
+					      sizeof(struct fsl_qdma_format) *
+					      status_size,
+					      &status_head->bus_addr,
+					      GFP_KERNEL);
 	if (!status_head->cq) {
 		devm_kfree(&pdev->dev, status_head);
 		return NULL;
@@ -1268,8 +1268,6 @@ static void fsl_qdma_cleanup_vchan(struct dma_device *dmadev)
 
 static void fsl_qdma_remove(struct platform_device *pdev)
 {
-	int i;
-	struct fsl_qdma_queue *status;
 	struct device_node *np = pdev->dev.of_node;
 	struct fsl_qdma_engine *fsl_qdma = platform_get_drvdata(pdev);
 
@@ -1277,12 +1275,6 @@ static void fsl_qdma_remove(struct platform_device *pdev)
 	fsl_qdma_cleanup_vchan(&fsl_qdma->dma_dev);
 	of_dma_controller_free(np);
 	dma_async_device_unregister(&fsl_qdma->dma_dev);
-
-	for (i = 0; i < fsl_qdma->block_number; i++) {
-		status = fsl_qdma->status[i];
-		dma_free_coherent(&pdev->dev, sizeof(struct fsl_qdma_format) *
-				status->n_cq, status->cq, status->bus_addr);
-	}
 }
 
 static const struct of_device_id fsl_qdma_dt_ids[] = {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/3] dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA
  2024-01-07 10:02 [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA Christophe JAILLET
@ 2024-01-07 10:02 ` Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 3/3] dmaengine: fsl-qdma: Remove a useless devm_kfree() Christophe JAILLET
  2024-01-22 16:25 ` [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Vinod Koul
  3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-01-07 10:02 UTC (permalink / raw)
  To: vkoul, jiaheng.fan, peng.ma, wen.he_1
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

This dma_alloc_coherent() is undone neither in the remove function, nor in
the error handling path of fsl_qdma_probe().

Switch to the managed version to fix both issues.

Fixes: b092529e0aa0 ("dmaengine: fsl-qdma: Add qDMA controller driver for Layerscape SoCs")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/fsl-qdma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/dma/fsl-qdma.c b/drivers/dma/fsl-qdma.c
index 38409e06040a..3a5595a1d442 100644
--- a/drivers/dma/fsl-qdma.c
+++ b/drivers/dma/fsl-qdma.c
@@ -514,11 +514,11 @@ static struct fsl_qdma_queue
 			queue_temp = queue_head + i + (j * queue_num);
 
 			queue_temp->cq =
-			dma_alloc_coherent(&pdev->dev,
-					   sizeof(struct fsl_qdma_format) *
-					   queue_size[i],
-					   &queue_temp->bus_addr,
-					   GFP_KERNEL);
+			dmam_alloc_coherent(&pdev->dev,
+					    sizeof(struct fsl_qdma_format) *
+					    queue_size[i],
+					    &queue_temp->bus_addr,
+					    GFP_KERNEL);
 			if (!queue_temp->cq)
 				return NULL;
 			queue_temp->block_base = fsl_qdma->block_base +
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/3] dmaengine: fsl-qdma: Remove a useless devm_kfree()
  2024-01-07 10:02 [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA Christophe JAILLET
  2024-01-07 10:02 ` [PATCH 2/3] dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA Christophe JAILLET
@ 2024-01-07 10:02 ` Christophe JAILLET
  2024-01-22 16:25 ` [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Vinod Koul
  3 siblings, 0 replies; 5+ messages in thread
From: Christophe JAILLET @ 2024-01-07 10:02 UTC (permalink / raw)
  To: vkoul, jiaheng.fan, peng.ma, wen.he_1
  Cc: dmaengine, linux-kernel, kernel-janitors, Christophe JAILLET

'status_head' is a managed resource. It will be freed automatically if
fsl_qdma_prep_status_queue(), and so fsl_qdma_probe(), fails.

Remove the redundant (and harmless) devm_kfree() call.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/dma/fsl-qdma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/fsl-qdma.c b/drivers/dma/fsl-qdma.c
index 3a5595a1d442..f167c96f3fe8 100644
--- a/drivers/dma/fsl-qdma.c
+++ b/drivers/dma/fsl-qdma.c
@@ -568,10 +568,9 @@ static struct fsl_qdma_queue
 					      status_size,
 					      &status_head->bus_addr,
 					      GFP_KERNEL);
-	if (!status_head->cq) {
-		devm_kfree(&pdev->dev, status_head);
+	if (!status_head->cq)
 		return NULL;
-	}
+
 	status_head->n_cq = status_size;
 	status_head->virt_head = status_head->cq;
 	status_head->virt_tail = status_head->cq;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths
  2024-01-07 10:02 [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Christophe JAILLET
                   ` (2 preceding siblings ...)
  2024-01-07 10:02 ` [PATCH 3/3] dmaengine: fsl-qdma: Remove a useless devm_kfree() Christophe JAILLET
@ 2024-01-22 16:25 ` Vinod Koul
  3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2024-01-22 16:25 UTC (permalink / raw)
  To: jiaheng.fan, peng.ma, wen.he_1, Christophe JAILLET
  Cc: dmaengine, linux-kernel, kernel-janitors


On Sun, 07 Jan 2024 11:02:02 +0100, Christophe JAILLET wrote:
> The first 2 patches are bug fixes related to missing dma_free_coherent() either
> in the remove function or in the error handling path of the probe.
> 
> They are compile tested only. So review with care.
> 
> The 3rd patch is only a clean up.
> 
> [...]

Applied, thanks!

[1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA
      commit: 968bc1d7203d384e72afe34124a1801b7af76514
[2/3] dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA
      commit: 3aa58cb51318e329d203857f7a191678e60bb714
[3/3] dmaengine: fsl-qdma: Remove a useless devm_kfree()
      commit: 0650006a93a2ce3b57f86e7f000347d9ae7737ef

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-22 16:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-07 10:02 [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Christophe JAILLET
2024-01-07 10:02 ` [PATCH 1/3] dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA Christophe JAILLET
2024-01-07 10:02 ` [PATCH 2/3] dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA Christophe JAILLET
2024-01-07 10:02 ` [PATCH 3/3] dmaengine: fsl-qdma: Remove a useless devm_kfree() Christophe JAILLET
2024-01-22 16:25 ` [PATCH 0/3] dmaengine: fsl-qdma: Fix some error handling paths Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®