]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
watchdog: dw_wdt: fix signedness bug in dw_wdt_top_in_seconds()
authorJisheng Zhang <jszhang@marvell.com>
Tue, 15 Dec 2015 14:25:27 +0000 (22:25 +0800)
committerWim Van Sebroeck <wim@iguana.be>
Sun, 27 Dec 2015 20:04:50 +0000 (21:04 +0100)
On 64bit platforms, "(1 << (16 + top)) / clk_get_rate(dw_wdt.clk)" is
sign-extended to 64bit then converted to unsigned 64bit, finally divide
the clk rate. If the top is the maximum TOP i.e 15, "(1 << (16 +15))"
will be sign-extended to 0xffffffff80000000, then converted to unsigned
0xffffffff80000000, which is a huge number, thus the final result is
wrong.

We fix this issue by giving usigned value(1U in this case) at first.

Let's assume clk rate is 25MHZ,
Before the patch:
dw_wdt_top_in_seconds(15) = -864612050

After the patch:
dw_wdt_top_in_seconds(15) = 85

Signed-off-by: Jisheng Zhang <jszhang@marvell.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
drivers/watchdog/dw_wdt.c

index 6ea0634345e99512eefec4f82ebcd8ee348bac82..8fefa4ad46d4d0a5fa928bf3c5694388b473e91b 100644 (file)
@@ -81,7 +81,7 @@ static inline int dw_wdt_top_in_seconds(unsigned top)
         * There are 16 possible timeout values in 0..15 where the number of
         * cycles is 2 ^ (16 + i) and the watchdog counts down.
         */
-       return (1 << (16 + top)) / clk_get_rate(dw_wdt.clk);
+       return (1U << (16 + top)) / clk_get_rate(dw_wdt.clk);
 }
 
 static int dw_wdt_get_top(void)