From: Rosen Penev rosenp@gmail.com
[ Upstream commit a33e3b667d2f004fdfae6b442bd4676f6c510abb ]
dma_alloc_wc is used but not dma_free_wc.
Signed-off-by: Rosen Penev rosenp@gmail.com Link: https://lore.kernel.org/r/20250821220942.10578-1-rosenp@gmail.com Signed-off-by: Vinod Koul vkoul@kernel.org Signed-off-by: Sasha Levin sashal@kernel.org ---
LLM Generated explanations, may be completely bogus:
YES
- The change fixes a real API mismatch: the descriptor pool is allocated with write‑combined attributes via `dma_alloc_wc`, but previously freed with `dma_free_coherent`. The patch replaces those frees with the correct `dma_free_wc` in both teardown paths: - `mv_xor_channel_remove`: drivers/dma/mv_xor.c:1016-1017 - `mv_xor_channel_add` error path (`err_free_dma`): drivers/dma/mv_xor.c:1166-1167 - The allocation site clearly uses WC memory for the descriptor pool: - `dma_alloc_wc(&pdev->dev, MV_XOR_POOL_SIZE, &mv_chan->dma_desc_pool, GFP_KERNEL)`: drivers/dma/mv_xor.c:1079-1082 - The surrounding comment explicitly notes the write-combine choice for performance and the need to handle it correctly. - Why this matters: - The DMA API requires pairing `dma_alloc_wc` with `dma_free_wc`. Freeing WC allocations with `dma_free_coherent` can fail to tear down mappings with the correct attributes, leading to DMA-API debug warnings, potential resource leaks, or attribute mismatches on some architectures. - The affected code runs in deterministic paths (channel remove and probe error unwind), so it’s directly user-visible on driver unload, device removal, or probe failures. - Risk assessment: - The fix is minimal and localized (two call-site substitutions), with no architectural or behavioral changes to normal data paths. - It is strictly a correctness fix and reduces the chance of DMA-API issues; it does not introduce new features or touch wider subsystems. - Stable backport criteria: - Fixes a concrete bug (API misuse) that can affect users (warnings, potential mapping/attribute teardown issues). - Small, self-contained change limited to `drivers/dma/mv_xor.c`. - Very low regression risk, as the free operations now match the established allocation method already in use. - Applicability note: - This should be backported to stable series where `mv_xor` allocates the descriptor pool with `dma_alloc_wc`. If an older stable tree still uses `dma_alloc_coherent` for this pool, the patch is not applicable there.
drivers/dma/mv_xor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c index 1fdcb0f5c9e72..5e83862960461 100644 --- a/drivers/dma/mv_xor.c +++ b/drivers/dma/mv_xor.c @@ -1013,7 +1013,7 @@ static int mv_xor_channel_remove(struct mv_xor_chan *mv_chan)
dma_async_device_unregister(&mv_chan->dmadev);
- dma_free_coherent(dev, MV_XOR_POOL_SIZE, + dma_free_wc(dev, MV_XOR_POOL_SIZE, mv_chan->dma_desc_pool_virt, mv_chan->dma_desc_pool); dma_unmap_single(dev, mv_chan->dummy_src_addr, MV_XOR_MIN_BYTE_COUNT, DMA_FROM_DEVICE); @@ -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,