From: Chris Packham <judge.packham@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH] watchdog: Handle timer wrap around
Date: Mon, 24 Feb 2020 13:20:33 +1300 [thread overview]
Message-ID: <20200224002033.17860-1-judge.packham@gmail.com> (raw)
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 <judge.packham@gmail.com>
---
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 <dm.h>
#include <errno.h>
#include <hang.h>
+#include <time.h>
#include <wdt.h>
#include <dm/device-internal.h>
#include <dm/lists.h>
@@ -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);
}
--
2.25.1
next reply other threads:[~2020-02-24 0:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 0:20 Chris Packham [this message]
2020-02-24 11:48 ` [PATCH] watchdog: Handle timer wrap around Stefan Roese
2020-03-16 14:19 ` Stefan Roese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200224002033.17860-1-judge.packham@gmail.com \
--to=judge.packham@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox