[PATCH 05/13] mmc: jz4740: Skip DMA cleanup in PIO mode during post_req

From: Lee Jones

Date: Mon Nov 23 2026 - 14:18:02 EST


When DMA channel acquisition fails during probe, the JZ4740 MMC driver
falls back to PIO mode with host->use_dma set to false and host->dma_tx
or host->dma_rx left holding an ERR_PTR() or released channel pointer.
Unlike jz4740_mmc_pre_request(), jz4740_mmc_post_request() does not
check host->use_dma before calling dmaengine_terminate_all() on error,
resulting in an invalid or dangling DMA channel pointer dereference
whenever a PIO data transfer encounters an error.

Return early from jz4740_mmc_post_request() when host->use_dma is false,
matching jz4740_mmc_pre_request().

Fixes: bb2f45927f8e ("mmc: jz4740: prepare next dma transfer in parallel with current transfer")
Closes: https://sashiko.dev/#/bug/linux-735efbcb-99f8-4d4a-8814-aa31e3634f29
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/mmc/host/jz4740_mmc.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
index 923cf1450de5..e398a575f2dc 100644
--- a/drivers/mmc/host/jz4740_mmc.c
+++ b/drivers/mmc/host/jz4740_mmc.c
@@ -392,6 +392,9 @@ static void jz4740_mmc_post_request(struct mmc_host *mmc,
struct jz4740_mmc_host *host = mmc_priv(mmc);
struct mmc_data *data = mrq->data;

+ if (!host->use_dma)
+ return;
+
if (data && data->host_cookie != COOKIE_UNMAPPED)
jz4740_mmc_dma_unmap(host, data);

--
2.56.1.750.gf70dc682cf-goog