y2038: alarm: fix half-second cut-off
authorArnd Bergmann <arnd@arndb.de>
Mon, 25 Nov 2019 20:25:46 +0000 (21:25 +0100)
committerArnd Bergmann <arnd@arndb.de>
Mon, 25 Nov 2019 20:52:35 +0000 (21:52 +0100)
Changing alarm_itimer accidentally broke the logic for arithmetic
rounding of half seconds in the return code.

Change it to a constant based on NSEC_PER_SEC, as suggested by
Ben Hutchings.

Fixes: bd40a175769d ("y2038: itimer: change implementation to timespec64")
Reported-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
kernel/time/itimer.c

index 5872db9bd5f76af175e37f543771f7715f92bf74..9e59c9ea92aa69b06e098c323d76c81f5f0f2200 100644 (file)
@@ -297,7 +297,7 @@ static unsigned int alarm_setitimer(unsigned int seconds)
         * better return too much than too little anyway
         */
        if ((!it_old.it_value.tv_sec && it_old.it_value.tv_nsec) ||
-             it_old.it_value.tv_nsec >= 500000)
+             it_old.it_value.tv_nsec >= (NSEC_PER_SEC / 2))
                it_old.it_value.tv_sec++;
 
        return it_old.it_value.tv_sec;