[PATCH] drivers/dma: replace dma_free_coherent with dma_free_wc

Zilin Guan posted 1 patch 2 weeks, 6 days ago
There is a newer version of this series
drivers/dma/mv_xor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] drivers/dma: replace dma_free_coherent with dma_free_wc
Posted by Zilin Guan 2 weeks, 6 days ago
The memory for the DMA descriptor pool (dma_desc_pool_virt) is allocated
by dma_alloc_wc, but it is freed by dma_free_coherent in the error
handling path. This is incorrect as DMA allocation and free functions
should be paired.

Using mismatched functions may lead to undefined behavior, memory leaks,
or system instability.

The fix is to use dma_free_wc to match the allocation function.

Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
 drivers/dma/mv_xor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 1fdcb0f5c9e7..58de208fc50d 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -1163,7 +1163,7 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
 err_free_irq:
 	free_irq(mv_chan->irq, mv_chan);
 err_free_dma:
-	dma_free_coherent(&pdev->dev, MV_XOR_POOL_SIZE,
+	dma_free_wc(&pdev->dev, MV_XOR_POOL_SIZE,
 			  mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool);
 err_unmap_dst:
 	dma_unmap_single(dma_dev->dev, mv_chan->dummy_dst_addr,
-- 
2.34.1
Re: [PATCH] drivers/dma: replace dma_free_coherent with dma_free_wc
Posted by Markus Elfring 2 weeks, 5 days ago
…
> The fix is to use dma_free_wc to match the allocation function.

* See also:
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc5#n94

* Would it be helpful to append parentheses to function names?

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?


Regards,
Markus