Skip to contentSkip to conversation

dmaengine: fsl-qdma: Fix some error handling paths

PATCH Applied Christophe JAILLET 2 participants 5 messages Jan 7, 2024 – Jan 22, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover dmaengine: fsl-qdma: Fix some error handling paths

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(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 dmaengine: fsl-qdma: Fix a memory leak related to the status queue DMA

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")
---
 drivers/dma/fsl-qdma.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)
drivers/dma/fsl-qdma.c +5 -13
index 47cb28468049..38409e06040a 100644
@@ -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[] = {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 dmaengine: fsl-qdma: Fix a memory leak related to the queue command DMA

In reply to 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")
---
 drivers/dma/fsl-qdma.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/dma/fsl-qdma.c +5 -5
index 38409e06040a..3a5595a1d442 100644
@@ -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 +
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/3 dmaengine: fsl-qdma: Remove a useless devm_kfree()

In reply to 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.

---
 drivers/dma/fsl-qdma.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/dma/fsl-qdma.c +2 -3
index 3a5595a1d442..f167c96f3fe8 100644
@@ -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;
Signature · 1 line
2.34.1
maintainer Applied
#4 lore raw
In reply to Christophe JAILLET
Quoted 8 lines · 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.

[...]

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,

Signature · 1 line
~Vinod