diff options
author | Ludovic Desroches <ludovic.desroches@atmel.com> | 2015-05-06 15:16:46 +0200 |
---|---|---|
committer | Sasha Levin <sasha.levin@oracle.com> | 2015-06-10 13:42:22 -0400 |
commit | 526639cb205517c4c83f7aef7884f00415990f3f (patch) | |
tree | 209ad6eea2370439e3fb9debd25f614252e8de3f | |
parent | 00f255cfbb795222c0bef47c019f9350197c4c2d (diff) | |
download | lwn-526639cb205517c4c83f7aef7884f00415990f3f.tar.gz lwn-526639cb205517c4c83f7aef7884f00415990f3f.zip |
mmc: atmel-mci: fix bad variable type for clkdiv
[ Upstream commit 60c8f783a18feb95ad967c87e9660caf09fb4700 ]
clkdiv is declared as an u32 but it can be set to a negative value
causing a huge divisor value. Change its type to int to avoid this case.
Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
Cc: <stable@vger.kernel.org> # 3.4 and later
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
-rw-r--r-- | drivers/mmc/host/atmel-mci.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c index 77250d4b1979..6423083c5238 100644 --- a/drivers/mmc/host/atmel-mci.c +++ b/drivers/mmc/host/atmel-mci.c @@ -1295,7 +1295,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) if (ios->clock) { unsigned int clock_min = ~0U; - u32 clkdiv; + int clkdiv; clk_prepare(host->mck); unprepare_clk = true; @@ -1324,7 +1324,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) /* Calculate clock divider */ if (host->caps.has_odd_clk_div) { clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; - if (clkdiv > 511) { + if (clkdiv < 0) { + dev_warn(&mmc->class_dev, + "clock %u too fast; using %lu\n", + clock_min, host->bus_hz / 2); + clkdiv = 0; + } else if (clkdiv > 511) { dev_warn(&mmc->class_dev, "clock %u too slow; using %lu\n", clock_min, host->bus_hz / (511 + 2)); |