From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH] time: Fix get_ticks being non-monotonic
Date: Tue, 1 Sep 2020 15:55:48 -0400 [thread overview]
Message-ID: <20200901195548.542737-1-seanga2@gmail.com> (raw)
get_ticks does not always succeed. Sometimes it can be called before the
timer has been initialized. If it does, it returns a negative errno.
This causes the timer to appear non-monotonic, because the value will
become much smaller after the timer is initialized.
No users of get_ticks which I checked handle errors of this kind. Further,
functions like tick_to_time mangle the result of get_ticks, making it very
unlikely that one could check for an error without suggesting a patch such
as this one.
This patch changes get_ticks to always return 0 when there is an error.
0 is the least unsigned integer, ensuring get_ticks appears monotonic. This
has the side effect of time apparently not passing until the timer is
initialized. However, without this patch, time does not pass anyway,
because the error value is likely to be the same.
Fixes: c8a7ba9e6a5
Signed-off-by: Sean Anderson <seanga2@gmail.com>
---
lib/time.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/time.c b/lib/time.c
index 47f8c84327..45750b6d36 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -91,13 +91,13 @@ uint64_t notrace get_ticks(void)
ret = dm_timer_init();
if (ret)
- return ret;
+ return 0;
#endif
}
ret = timer_get_count(gd->timer, &count);
if (ret)
- return ret;
+ return 0;
return count;
}
--
2.28.0
next reply other threads:[~2020-09-01 19:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 19:55 Sean Anderson [this message]
2020-09-07 1:43 ` [PATCH] time: Fix get_ticks being non-monotonic Simon Glass
2020-09-07 2:02 ` Sean Anderson
2020-09-07 13:57 ` Simon Glass
2020-09-07 15:51 ` Sean Anderson
2020-09-08 23:56 ` Simon Glass
2020-09-08 23:59 ` Sean Anderson
2020-09-09 0:01 ` Simon Glass
2020-09-09 0:02 ` Sean Anderson
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=20200901195548.542737-1-seanga2@gmail.com \
--to=seanga2@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