[PATCH 07/13] mmc: tifm_sd: Synchronise timeout handler with request completion

From: Lee Jones

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


tifm_sd_end_cmd() deletes host->timer with timer_delete() under
sock->lock, clears host->req to NULL, and completes the request via
mmc_request_done(). Because timer_delete() does not wait for an already
executing timer callback and tifm_sd_abort() reads the active command
opcode from host->req without holding sock->lock, a concurrent timeout
expiry can dereference a NULL or freed struct mmc_request and spuriously
eject the card after the request has already completed.

Serialise tifm_sd_abort() on sock->lock, return early if host->req has
already been cleared or the socket is being ejected, and snapshot the
command opcode and flags before releasing sock->lock prior to calling
tifm_eject().

Fixes: 91f8d0118a0e ("tifm: layout fixes, small changes to comments and printfs")
Closes: https://sashiko.dev/#/bug/linux-6535b228-4464-4a24-8fea-e969201c0f95
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/mmc/host/tifm_sd.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 28ab2526dab1..30935214d17c 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -776,12 +776,24 @@ static void tifm_sd_end_cmd(struct work_struct *t)
static void tifm_sd_abort(struct timer_list *t)
{
struct tifm_sd *host = timer_container_of(host, t, timer);
+ struct tifm_dev *sock = host->dev;
+ unsigned int opcode, cmd_flags;
+ unsigned long flags;
+
+ spin_lock_irqsave(&sock->lock, flags);
+ if (!host->req || host->eject) {
+ spin_unlock_irqrestore(&sock->lock, flags);
+ return;
+ }
+ opcode = host->req->cmd->opcode;
+ cmd_flags = host->cmd_flags;
+ spin_unlock_irqrestore(&sock->lock, flags);

pr_err("%s : card failed to respond for a long period of time "
"(%x, %x)\n",
- dev_name(&host->dev->dev), host->req->cmd->opcode, host->cmd_flags);
+ dev_name(&sock->dev), opcode, cmd_flags);

- tifm_eject(host->dev);
+ tifm_eject(sock);
}

static void tifm_sd_ios(struct mmc_host *mmc, struct mmc_ios *ios)
--
2.56.1.750.gf70dc682cf-goog