Skip to contentSkip to conversation

mmc: fix division by zero when cal erase timeout

PATCH In review Chuanxiao Dong 1 participant 1 message Feb 12, 2011 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH v4 3/3 mmc: fix division by zero when cal erase timeout

Since if clock gating feature is enabled, the clock frequency may be zero when host clock is gated. In such scenario, mmc_set_mmc_erase_timeout() may have a division by zero bug.

So this patch used mmc_host_clk_rate() to fix this.

---
 drivers/mmc/core/core.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
drivers/mmc/core/core.c +8 -2
index 0eb27aa..2f4576d 100644
@@ -1201,8 +1201,14 @@ static void mmc_set_mmc_erase_timeout(struct mmc_card *card,
 		 * less but not that much less, so fudge it by multiplying by 2.
 		 */
 		timeout_clks <<= 1;
-		timeout_us += (timeout_clks * 1000) /
-			      (card->host->ios.clock / 1000);
+
+		/*
+		 * at this moment, host controller maybe clock gated, so make
+		 * sure we can get a correct host clock freq.
+		 */
+		if (mmc_host_clk_rate(card->host))
+			timeout_us += (timeout_clks * 1000) /
+				      (mmc_host_clk_rate(card->host) / 1000);
 
 		erase_timeout = timeout_us / 1000;
 
Signature · 1 line
1.6.6.1