From d33b43a4dcc4ae3cd178793c139756af77e42bde Mon Sep 17 00:00:00 2001 From: Christophe Kerello Date: Tue, 6 Jun 2023 14:50:02 +0200 Subject: [PATCH] mmc: mmci: stm32: fix max busy timeout calculation The way that the timeout is currently calculated could lead to a u64 timeout value. this value is then cast in a u32 register that leads to mmc erase failed issue with some SD cards. Change-Id: Ibe2682ba42e878c30b61471672800f5fc04ce87c Signed-off-by: Christophe Kerello Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/311057 Tested-by: Eric FOURMONT Reviewed-by: Eric FOURMONT Domain-Review: Eric FOURMONT --- drivers/mmc/host/mmci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index a47a13fa72c5..e42a8eb1e3eb 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1746,7 +1746,8 @@ static void mmci_set_max_busy_timeout(struct mmc_host *mmc) return; if (host->variant->busy_timeout && mmc->actual_clock) - max_busy_timeout = ~0UL / (mmc->actual_clock / MSEC_PER_SEC); + max_busy_timeout = U32_MAX / DIV_ROUND_UP(mmc->actual_clock, + MSEC_PER_SEC); mmc->max_busy_timeout = max_busy_timeout; }