[PATCH] powerpc/pasemi: Fix pasemi_dma_free_buf()

From: Thomas Fourier

Date: Thu Nov 26 2026 - 03:21:52 EST


dma_free_coherent() is called with the wrong arguments. The two last
arguments must be the virtual address and the DMA address but the
DMA address and the allocation flags are passed. If this function were
called, it would call kfree() on a DMA address and dma_unmap() on the
allocation flag.

Add the buffer argument to pasemi_dma_free_buf() and pass the right
arguments to dma_free_coherent().

Fixes: 8ee9d8577935 ("pasemi: DMA engine management library")
Signed-off-by: Thomas Fourier <fourier.thomas@xxxxxxxxx>
---
arch/powerpc/include/asm/pasemi_dma.h | 2 +-
arch/powerpc/platforms/pasemi/dma_lib.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/include/asm/pasemi_dma.h b/arch/powerpc/include/asm/pasemi_dma.h
index 712a0b32120f..9285a38ff18a 100644
--- a/arch/powerpc/include/asm/pasemi_dma.h
+++ b/arch/powerpc/include/asm/pasemi_dma.h
@@ -508,7 +508,7 @@ extern void pasemi_dma_free_ring(struct pasemi_dmachan *chan);
extern void *pasemi_dma_alloc_buf(struct pasemi_dmachan *chan, int size,
dma_addr_t *handle);
extern void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
- dma_addr_t *handle);
+ void *buf, dma_addr_t *handle);

/* Routines to allocate flags (events) for channel synchronization */
extern int pasemi_dma_alloc_flag(void);
diff --git a/arch/powerpc/platforms/pasemi/dma_lib.c b/arch/powerpc/platforms/pasemi/dma_lib.c
index 1be1f18f6f09..d33feb32c0a1 100644
--- a/arch/powerpc/platforms/pasemi/dma_lib.c
+++ b/arch/powerpc/platforms/pasemi/dma_lib.c
@@ -356,14 +356,15 @@ EXPORT_SYMBOL(pasemi_dma_alloc_buf);
/* pasemi_dma_free_buf - Free a buffer used for DMA
* @chan: Channel the buffer was allocated for
* @size: Size of buffer in bytes
+ * @buf: Virtual address of the buffer
* @handle: DMA handle
*
* Frees a previously allocated buffer.
*/
-void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
+void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size, void *buf,
dma_addr_t *handle)
{
- dma_free_coherent(&dma_pdev->dev, size, handle, GFP_KERNEL);
+ dma_free_coherent(&dma_pdev->dev, size, buf, *handle);
}
EXPORT_SYMBOL(pasemi_dma_free_buf);

--
2.53.0