Skip to contentSkip to conversation

bfin: fix max timeout calculation

PATCH New Mike Frysinger 1 participant 1 message Feb 16, 2010 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bfin: fix max timeout calculation

Relying on overflow/wrap around isn't exact because if you wrap far enough, you get back to "valid" values.

---
 drivers/watchdog/bfin_wdt.c |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
drivers/watchdog/bfin_wdt.c +7 -6
index c7b3f9d..2159e66 100644
@@ -1,9 +1,8 @@
 /*
  * Blackfin On-Chip Watchdog Driver
- *  Supports BF53[123]/BF53[467]/BF54[2489]/BF561
  *
  * Originally based on softdog.c
- * Copyright 2006-2007 Analog Devices Inc.
+ * Copyright 2006-2010 Analog Devices Inc.
  * Copyright 2006-2007 Michele d'Amico
  * Copyright 1996 Alan Cox <[email protected]>
  *
@@ -137,13 +136,15 @@ static int bfin_wdt_running(void)
  */
 static int bfin_wdt_set_timeout(unsigned long t)
 {
-	u32 cnt;
+	u32 cnt, max_t, sclk;
 	unsigned long flags;
 
-	stampit();
+	sclk = get_sclk();
+	max_t = -1 / sclk;
+	cnt = t * sclk;
+	stamp("maxtimeout=%us newtimeout=%lus (cnt=%#x)", max_t, t, cnt);
 
-	cnt = t * get_sclk();
-	if (cnt < get_sclk()) {
+	if (t > max_t) {
 		printk(KERN_WARNING PFX "timeout value is too large\n");
 		return -EINVAL;
 	}
Signature · 1 line
1.7.0