All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] watchdog: Handle timer wrap around
@ 2020-02-24  0:20 Chris Packham
  2020-02-24 11:48 ` Stefan Roese
  2020-03-16 14:19 ` Stefan Roese
  0 siblings, 2 replies; 3+ messages in thread
From: Chris Packham @ 2020-02-24  0:20 UTC (permalink / raw)
  To: u-boot

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

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

* [PATCH] watchdog: Handle timer wrap around
  2020-02-24  0:20 [PATCH] watchdog: Handle timer wrap around Chris Packham
@ 2020-02-24 11:48 ` Stefan Roese
  2020-03-16 14:19 ` Stefan Roese
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2020-02-24 11:48 UTC (permalink / raw)
  To: u-boot

On 24.02.20 01:20, Chris Packham wrote:
> 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>

Reviewed-by: Stefan Roese <sr@denx.de>

Thanks,
Stefan

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

* [PATCH] watchdog: Handle timer wrap around
  2020-02-24  0:20 [PATCH] watchdog: Handle timer wrap around Chris Packham
  2020-02-24 11:48 ` Stefan Roese
@ 2020-03-16 14:19 ` Stefan Roese
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Roese @ 2020-03-16 14:19 UTC (permalink / raw)
  To: u-boot

On 24.02.20 01:20, Chris Packham wrote:
> 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>

Applied to u-boot-marvell/master.

Thanks,
Stefan

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

end of thread, other threads:[~2020-03-16 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-24  0:20 [PATCH] watchdog: Handle timer wrap around Chris Packham
2020-02-24 11:48 ` Stefan Roese
2020-03-16 14:19 ` Stefan Roese

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.