summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorLudovic Desroches <ludovic.desroches@atmel.com>2015-05-06 16:16:46 +0300
committerZefan Li <lizefan@huawei.com>2015-09-18 04:20:41 +0300
commitcc81c42b3fe5cac84f025715260d9bff305e9968 (patch)
treeffa6b9484b3d8f2c70fa1dfeb2da6e9b8916dd8e /drivers
parentf126db0e684121668bc0ff4889dccd8f25a333b5 (diff)
downloadlinux-cc81c42b3fe5cac84f025715260d9bff305e9968.tar.xz
mmc: atmel-mci: fix bad variable type for clkdiv
commit 60c8f783a18feb95ad967c87e9660caf09fb4700 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: Ludovic Desroches <ludovic.desroches@atmel.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Zefan Li <lizefan@huawei.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mmc/host/atmel-mci.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index e6f08d945709..c300cc4dcda0 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1125,7 +1125,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;
spin_lock_bh(&host->lock);
if (!host->mode_reg) {
@@ -1150,7 +1150,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));