]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.14.44/mmc-atmel-mci-fix-bad-variable-type-for-clkdiv.patch
drop queue-4.14/mips-make-sure-dt-memory-regions-are-valid.patch
[thirdparty/kernel/stable-queue.git] / releases / 3.14.44 / mmc-atmel-mci-fix-bad-variable-type-for-clkdiv.patch
1 From 60c8f783a18feb95ad967c87e9660caf09fb4700 Mon Sep 17 00:00:00 2001
2 From: Ludovic Desroches <ludovic.desroches@atmel.com>
3 Date: Wed, 6 May 2015 15:16:46 +0200
4 Subject: mmc: atmel-mci: fix bad variable type for clkdiv
5
6 From: Ludovic Desroches <ludovic.desroches@atmel.com>
7
8 commit 60c8f783a18feb95ad967c87e9660caf09fb4700 upstream.
9
10 clkdiv is declared as an u32 but it can be set to a negative value
11 causing a huge divisor value. Change its type to int to avoid this case.
12
13 Signed-off-by: Ludovic Desroches <ludovic.desroches@atmel.com>
14 Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16
17 ---
18 drivers/mmc/host/atmel-mci.c | 9 +++++++--
19 1 file changed, 7 insertions(+), 2 deletions(-)
20
21 --- a/drivers/mmc/host/atmel-mci.c
22 +++ b/drivers/mmc/host/atmel-mci.c
23 @@ -1300,7 +1300,7 @@ static void atmci_set_ios(struct mmc_hos
24
25 if (ios->clock) {
26 unsigned int clock_min = ~0U;
27 - u32 clkdiv;
28 + int clkdiv;
29
30 clk_prepare(host->mck);
31 unprepare_clk = true;
32 @@ -1329,7 +1329,12 @@ static void atmci_set_ios(struct mmc_hos
33 /* Calculate clock divider */
34 if (host->caps.has_odd_clk_div) {
35 clkdiv = DIV_ROUND_UP(host->bus_hz, clock_min) - 2;
36 - if (clkdiv > 511) {
37 + if (clkdiv < 0) {
38 + dev_warn(&mmc->class_dev,
39 + "clock %u too fast; using %lu\n",
40 + clock_min, host->bus_hz / 2);
41 + clkdiv = 0;
42 + } else if (clkdiv > 511) {
43 dev_warn(&mmc->class_dev,
44 "clock %u too slow; using %lu\n",
45 clock_min, host->bus_hz / (511 + 2));