newbie y2038 bug, patch

Dan Kegel (dank@alumni.caltech.edu)
Fri, 19 Nov 1999 00:23:15 -0800


Reading "Linux Core Kernel Commentary" at bedtime,
I noticed what looks like a wraparound bug in
do_timer_interrupt() that could cause set_rtc_mmss
to get called once per second (instead of once
every 11 minutes) for an 11 minute interval near
the wraparound of xtime.tv_sec in the year 2038.

Uh, ok, so that's not the most urgent bug to fix :-)
but could somebody check my logic? Here would be
the patch (using my favorite idiom for checking
timers without getting caught by wraparound:
turning the unsigned comparison into a signed comparison
with zero):

--- linux-2.2.12/arch/i386/kernel/time.c Fri Nov 19 01:06:27 1999
+++ linux/arch/i386/kernel/time.c Fri Nov 19 01:22:18 1999
@@ -383,7 +383,7 @@
* called as close as possible to 500 ms before the new second
starts.
*/
if ((time_status & STA_UNSYNC) == 0 &&
- xtime.tv_sec > last_rtc_update + 660 &&
+ (0 > ((long)(last_rtc_update + 660 - xtime.tv_sec))) &&
xtime.tv_usec >= 500000 - ((unsigned) tick) / 2 &&
xtime.tv_usec <= 500000 + ((unsigned) tick) / 2) {
if (set_rtc_mmss(xtime.tv_sec) ==
0)

Thanks,
Dan

-- 
(The above is just my personal opinion; I don't speak for my employer,
 except on the occasional talk show.)

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/