Skip to content

Commit e3fab2f

Browse files
geertuKAGA-KOKO
authored andcommitted
ntp: Fix RTC synchronization on 32-bit platforms
Due to an integer overflow, RTC synchronization now happens every 2s instead of the intended 11 minutes. Fix this by forcing 64-bit arithmetic for the sync period calculation. Annotate the other place which multiplies seconds for consistency as well. Fixes: c9e6189 ("ntp: Make the RTC synchronization more reliable") Signed-off-by: Geert Uytterhoeven <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent aba428a commit e3fab2f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

kernel/time/ntp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ int second_overflow(time64_t secs)
498498
static void sync_hw_clock(struct work_struct *work);
499499
static DECLARE_WORK(sync_work, sync_hw_clock);
500500
static struct hrtimer sync_hrtimer;
501-
#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC)
501+
#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC)
502502

503503
static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
504504
{
@@ -512,7 +512,7 @@ static void sched_sync_hw_clock(unsigned long offset_nsec, bool retry)
512512
ktime_t exp = ktime_set(ktime_get_real_seconds(), 0);
513513

514514
if (retry)
515-
exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec);
515+
exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);
516516
else
517517
exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec);
518518

0 commit comments

Comments
 (0)