summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2021-11-30 17:03:08 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2021-12-07 10:08:16 +0100
commit6503eb21c6043b74a4a92d9b92057cbf45b6f313 (patch)
treed1a5927055058b734cd3e2b40d86b343d88e9436
parent70f6dd77051de4f72d0a96f44f4dbc68faae0fc6 (diff)
downloadbarebox-6503eb21c6043b74a4a92d9b92057cbf45b6f313.tar.gz
barebox-6503eb21c6043b74a4a92d9b92057cbf45b6f313.tar.xz
scripts/kwboot: Fix normalizing timeval
If tv.tv_usec is 1000000 the structure needs normalizing, too. So the right check would be: if (tv.tv_usec >= 1000000) { ... But as normalizing doesn't destroy anything even for smaller values, just do it unconditionally to simplify a bit. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.barebox.org/20211130160308.316863-1-u.kleine-koenig@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--scripts/kwboot.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/scripts/kwboot.c b/scripts/kwboot.c
index 60e8a69d18..1cbb456935 100644
--- a/scripts/kwboot.c
+++ b/scripts/kwboot.c
@@ -147,12 +147,11 @@ kwboot_tty_recv(int fd, void *buf, size_t len, int timeo)
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
- tv.tv_sec = 0;
tv.tv_usec = timeo * 1000;
- if (tv.tv_usec > 1000000) {
- tv.tv_sec += tv.tv_usec / 1000000;
- tv.tv_usec %= 1000000;
- }
+
+ /* normalize timeval */
+ tv.tv_sec = tv.tv_usec / 1000000;
+ tv.tv_usec %= 1000000;
do {
nfds = select(fd + 1, &rfds, NULL, NULL, &tv);