From patchwork Mon Feb 24 00:20:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 236738 List-Id: U-Boot discussion From: judge.packham at gmail.com (Chris Packham) Date: Mon, 24 Feb 2020 13:20:33 +1300 Subject: [PATCH] watchdog: Handle timer wrap around Message-ID: <20200224002033.17860-1-judge.packham@gmail.com> On some platforms/architectures the value from get_timer() can wrap. This is particularly problematic when long-running code needs to measure a time difference as is the case with watchdog_reset() which tries to avoid tickling the watchdog too frequently. Use time_after() from time.h instead of a plain > comparison to avoid any issues with the time wrapping on a system that has been sitting in u-boot for a long time. Signed-off-by: Chris Packham Reviewed-by: Stefan Roese --- drivers/watchdog/wdt-uclass.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/watchdog/wdt-uclass.c b/drivers/watchdog/wdt-uclass.c index cf1c52747397..d9e4dc7cb8a4 100644 --- a/drivers/watchdog/wdt-uclass.c +++ b/drivers/watchdog/wdt-uclass.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -83,7 +84,7 @@ void watchdog_reset(void) /* Do not reset the watchdog too often */ now = get_timer(0); - if (now > next_reset) { + if (time_after(now, next_reset)) { next_reset = now + 1000; /* reset every 1000ms */ wdt_reset(gd->watchdog_dev); }