mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds
@ 2017-08-15  2:45 Huibin Hong
  2017-08-15  4:49 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Huibin Hong @ 2017-08-15  2:45 UTC (permalink / raw)
  To: linux
  Cc: huangtao, Huibin Hong, Wim Van Sebroeck, linux-watchdog, linux-kernel

If top is 15, (1 << (16 + top)) may be negative.

Signed-off-by: Huibin Hong <huibin.hong@rock-chips.com>
---

Changes in v2:
    - Rebase mainline Linux 4.13-rc5

 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 36be987..59ed958 100644
--- a/drivers/watchdog/dw_wdt.c
+++ b/drivers/watchdog/dw_wdt.c
@@ -72,7 +72,9 @@ static inline int dw_wdt_top_in_seconds(struct dw_wdt *dw_wdt, 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 (1U << (16 + top)) / dw_wdt->rate;
+	unsigned int cycles = 1 << (16 + top);
+
+	return (cycles / clk_get_rate(dw_wdt.clk));
 }
 
 static int dw_wdt_get_top(struct dw_wdt *dw_wdt)
-- 
1.9.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-08-16 20:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-15  2:45 [PATCH v2] watchdog: dw_wdt: fix overflow issue in dw_wdt_top_in_seconds Huibin Hong
2017-08-15  4:49 ` Guenter Roeck
2017-08-16 20:24 ` kbuild test robot
2017-08-16 20:30 ` kbuild test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®