[PATCH 06/13] mmc: renesas_sdhi: Guard host->cmd access in internal DMAC issue work

From: Lee Jones

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


renesas_sdhi_internal_dmac_issue_work_fn() unmasks TMIO_STAT_DATAEND and
dereferences host->cmd without holding host->lock or checking that
host->cmd is still non-NULL. If tmio_mmc_reset_work() times out and
clears host->cmd under host->lock after tmio_mmc_cmd_irq() queues
host->dma_issue, or if unmasking TMIO_STAT_DATAEND allows a concurrent
data-end error completion to clear host->cmd via
tmio_mmc_finish_request(), evaluating host->cmd->error triggers a NULL
pointer dereference. Unmasking TMIO_STAT_DATAEND outside host->lock
also races with concurrent updates to host->sdcard_irq_mask.

Acquire host->lock across renesas_sdhi_internal_dmac_issue_work_fn() and
bail out if host->cmd has already been cleared, matching the sibling
system DMAC implementation.

Fixes: c330601c9c93 ("mmc: renesas_sdhi: take DMA end interrupts into account")
Closes: https://sashiko.dev/#/bug/linux-57271e16-2f7e-4151-a686-57ab2474fe6f
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/mmc/host/renesas_sdhi_internal_dmac.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/mmc/host/renesas_sdhi_internal_dmac.c b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
index 0c3967f758c2..6831fc34cd22 100644
--- a/drivers/mmc/host/renesas_sdhi_internal_dmac.c
+++ b/drivers/mmc/host/renesas_sdhi_internal_dmac.c
@@ -450,6 +450,13 @@ static void renesas_sdhi_internal_dmac_issue_work_fn(struct work_struct *work)
{
struct tmio_mmc_host *host = from_work(host, work, dma_issue);
struct renesas_sdhi *priv = host_to_priv(host);
+ unsigned long flags;
+
+ spin_lock_irqsave(&host->lock, flags);
+ if (!host->cmd) {
+ spin_unlock_irqrestore(&host->lock, flags);
+ return;
+ }

tmio_mmc_enable_mmc_irqs(host, TMIO_STAT_DATAEND);

@@ -462,6 +469,7 @@ static void renesas_sdhi_internal_dmac_issue_work_fn(struct work_struct *work)
if (test_bit(SDHI_DMA_END_FLAG_ACCESS, &priv->dma_priv.end_flags))
queue_work(system_bh_wq, &priv->dma_priv.dma_complete);
}
+ spin_unlock_irqrestore(&host->lock, flags);
}

static bool renesas_sdhi_internal_dmac_complete(struct tmio_mmc_host *host)
--
2.56.1.750.gf70dc682cf-goog