[PATCH 04/13] mmc: meson-gx: Fail request when descriptor chain DMA mapping fails

Lee Jones lee at kernel.org
Mon Nov 23 11:15:48 PST 2026


meson_mmc_pre_req() flags eligible transfers with
SD_EMMC_DESC_CHAIN_MODE before mapping the scatterlist with
dma_map_sg().  If dma_map_sg() fails and returns 0, meson_mmc_pre_req()
logs an error but leaves SD_EMMC_DESC_CHAIN_MODE set with
data->sg_count equal to 0.  When meson_mmc_request() subsequently
dispatches the transfer to meson_mmc_desc_chain_transfer(), the
for_each_sg() loop executes zero iterations and
desc[data->sg_count - 1].cmd_cfg writes to desc[-1], corrupting memory
immediately preceding the coherent descriptor buffer before starting the
DMA engine.

Check that data->sg_count is non-zero before starting a descriptor chain
request in meson_mmc_request() and complete the request with -EINVAL if
mapping failed.

Fixes: 79ed05e329c3 ("mmc: meson-gx: add support for descriptor chain mode")
Closes: https://sashiko.dev/#/bug/linux-e22e5db6-4232-447c-82b0-6850ad48d2a2
Cc: stable at vger.kernel.org
Signed-off-by: Lee Jones <lee at kernel.org>
---
 drivers/mmc/host/meson-gx-mmc.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c
index d2b9b5df9596..f859d9ac0a0a 100644
--- a/drivers/mmc/host/meson-gx-mmc.c
+++ b/drivers/mmc/host/meson-gx-mmc.c
@@ -914,6 +914,13 @@ static void meson_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
 	if (host->needs_pre_post_req)
 		meson_mmc_pre_req(mmc, mrq);
 
+	if (mrq->data && meson_mmc_desc_chain_mode(mrq->data) &&
+	    !mrq->data->sg_count) {
+		mrq->cmd->error = -EINVAL;
+		mmc_request_done(mmc, mrq);
+		return;
+	}
+
 	/* Stop execution */
 	writel(0, host->regs + SD_EMMC_START);
 
-- 
2.56.1.750.gf70dc682cf-goog




More information about the linux-arm-kernel mailing list