Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1697956 > unrolled thread

[PATCH] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds

Started byHuibin Hong <huibin.hong@rock-chips.com>
First post2017-07-27 15:00 +0200
Last post2017-07-27 15:00 +0200
Articles 1 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds Huibin Hong <huibin.hong@rock-chips.com> - 2017-07-27 15:00 +0200

#1697956 — [PATCH] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds

FromHuibin Hong <huibin.hong@rock-chips.com>
Date2017-07-27 15:00 +0200
Subject[PATCH] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds
Message-ID<u7Qyt-6dA-9@gated-at.bofh.it>
If top is 15, (1 << (16 + top)) may be negative.

Change-Id: I76e4a603a54f093e64a4b266008570e3afcdb35a
Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
---
 drivers/watchdog/dw_wdt.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/watchdog/dw_wdt.c b/drivers/watchdog/dw_wdt.c
index 6ea0634..059c974 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -81,7 +81,9 @@ 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);
+	unsigned int cycles = 1 << (16 + top);
+
+	return cycles / clk_get_rate(dw_wdt.clk);
 }
 
 static int dw_wdt_get_top(void)
-- 
1.9.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web