Commit 2b5b809f authored by Ludovic Desroches's avatar Ludovic Desroches Committed by Kamal Mostafa

mmc: atmel-mci: fix bad variable type for clkdiv

commit 60c8f783 upstream.

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: default avatarLudovic Desroches <ludovic.desroches@atmel.com>
Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
parent d9f5ff79
...@@ -1300,7 +1300,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -1300,7 +1300,7 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
if (ios->clock) { if (ios->clock) {
unsigned int clock_min = ~0U; unsigned int clock_min = ~0U;
u32 clkdiv; int clkdiv;
clk_prepare(host->mck); clk_prepare(host->mck);
unprepare_clk = true; unprepare_clk = true;
...@@ -1329,7 +1329,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) ...@@ -1329,7 +1329,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
/* Calculate clock divider */ /* Calculate clock divider */
if (host->caps.has_odd_clk_div) { if (host->caps.has_odd_clk_div) {
clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2; 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, dev_warn(&mmc->class_dev,
"clock %u too slow; using %lu\n", "clock %u too slow; using %lu\n",
clock_min, host->bus_hz / (511 + 2)); clock_min, host->bus_hz / (511 + 2));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment