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
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 <[email protected]>
---
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
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 <[email protected]>
---
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
'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 <[email protected]>
---
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
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