Skip to content

Commit 8d56a1e

Browse files
Christophe KerelloPatrice Chotard
authored andcommitted
mmc: stm32_sdmmc2: avoid infinite while loop
Avoid unlimited while loop by adding a timeout. The timeout is calculated based on a minimal throughput of 256 KB/s. The timeout is set at least to 2 seconds. Change-Id: I690ec47a9b82ca2fd9f5edbd43d1700cedbcae40 Signed-off-by: Christophe Kerello <christophe.kerello@foss.st.com> Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/455777 ACI: CITOOLS <MDG-smet-aci-reviews@list.st.com> Tested-by: Christophe KERELLO <christophe.kerello@st.com> Domain-Review: Christophe KERELLO <christophe.kerello@st.com> Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com> Reviewed-by: Christophe KERELLO <christophe.kerello@st.com>
1 parent c9fcfb1 commit 8d56a1e

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

drivers/mmc/stm32_sdmmc2.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,29 @@ static int stm32_sdmmc2_end_data(struct udevice *dev,
385385
u32 mask = SDMMC_STA_DCRCFAIL | SDMMC_STA_DTIMEOUT |
386386
SDMMC_STA_IDMATE | SDMMC_STA_DATAEND;
387387
u32 status;
388+
unsigned long timeout_msecs = ctx->data_length >> 8;
389+
unsigned long start_timeout;
390+
391+
/* At least, a timeout of 2 seconds is set */
392+
if (timeout_msecs < 2000)
393+
timeout_msecs = 2000;
388394

389395
if (data->flags & MMC_DATA_READ)
390396
mask |= SDMMC_STA_RXOVERR;
391397
else
392398
mask |= SDMMC_STA_TXUNDERR;
393399

400+
start_timeout = get_timer(0);
394401
status = readl(plat->base + SDMMC_STA);
395-
while (!(status & mask))
402+
while (!(status & mask)) {
403+
if (get_timer(start_timeout) > timeout_msecs) {
404+
ctx->dpsm_abort = true;
405+
return -ETIMEDOUT;
406+
}
407+
408+
schedule();
396409
status = readl(plat->base + SDMMC_STA);
410+
}
397411

398412
/*
399413
* Need invalidate the dcache again to avoid any

0 commit comments

Comments
 (0)