[PATCH] mtd: rawnand: marvell: Fix potential DMA buffer leak

Guangshuo Li liguangshuo at mail.sdu.edu.cn
Tue Nov 10 06:32:24 PST 2026


The bounce buffer allocated by marvell_nfc_init_dma() is not freed on
probe failure or removal. Releasing the controller loses the buffer.

Use a device-managed allocation so the buffer is freed after the DMA
channel has been shut down.

This issue was found by our static analysis tool under development.

Fixes: 02f26ecf8c77 ("mtd: nand: add reworked Marvell NAND controller driver")
Cc: stable at vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo at mail.sdu.edu.cn>
---
 drivers/mtd/nand/raw/marvell_nand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/raw/marvell_nand.c b/drivers/mtd/nand/raw/marvell_nand.c
index e5fa5540e80a..1adf4dcee93f 100644
--- a/drivers/mtd/nand/raw/marvell_nand.c
+++ b/drivers/mtd/nand/raw/marvell_nand.c
@@ -2862,7 +2862,7 @@ static int marvell_nfc_init_dma(struct marvell_nfc *nfc)
 	 * for DMA transfers and then copy the desired amount of data to
 	 * the provided buffer.
 	 */
-	nfc->dma_buf = kmalloc(MAX_CHUNK_SIZE, GFP_KERNEL | GFP_DMA);
+	nfc->dma_buf = devm_kmalloc(nfc->dev, MAX_CHUNK_SIZE, GFP_KERNEL | GFP_DMA);
 	if (!nfc->dma_buf) {
 		ret = -ENOMEM;
 		goto release_channel;

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4



More information about the linux-mtd mailing list