Skip to content

Commit df3c6e0

Browse files
Sangwook ShinWim Van Sebroeck
authored andcommitted
watchdog: s3c2410_wdt: Fix max_timeout being calculated larger
Fix the issue of max_timeout being calculated larger than actual value. The calculation result of freq / (S3C2410_WTCON_PRESCALE_MAX + 1) / S3C2410_WTCON_MAXDIV is smaller than the actual value because the remainder is discarded during the calculation process. This leads to a larger calculated value for max_timeout compared to the actual settable value. To resolve this issue, the order of calculations in the computation process has been adjusted. Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org> Signed-off-by: Sangwook Shin <sw617.shin@samsung.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
1 parent e76bb4e commit df3c6e0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/watchdog/s3c2410_wdt.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/mfd/syscon.h>
2828
#include <linux/regmap.h>
2929
#include <linux/delay.h>
30+
#include <linux/math64.h>
3031

3132
#define S3C2410_WTCON 0x00
3233
#define S3C2410_WTDAT 0x04
@@ -410,9 +411,14 @@ static inline unsigned long s3c2410wdt_get_freq(struct s3c2410_wdt *wdt)
410411
static inline unsigned int s3c2410wdt_max_timeout(struct s3c2410_wdt *wdt)
411412
{
412413
const unsigned long freq = s3c2410wdt_get_freq(wdt);
414+
const u64 n_max = (u64)(S3C2410_WTCON_PRESCALE_MAX + 1) *
415+
S3C2410_WTCON_MAXDIV * S3C2410_WTCNT_MAXCNT;
416+
u64 t_max = div64_ul(n_max, freq);
413417

414-
return S3C2410_WTCNT_MAXCNT / (freq / (S3C2410_WTCON_PRESCALE_MAX + 1)
415-
/ S3C2410_WTCON_MAXDIV);
418+
if (t_max > UINT_MAX)
419+
t_max = UINT_MAX;
420+
421+
return t_max;
416422
}
417423

418424
static int s3c2410wdt_disable_wdt_reset(struct s3c2410_wdt *wdt, bool mask)

0 commit comments

Comments
 (0)