lkml.org 
[lkml]   [2021]   [Jan]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] ntp: Fix RTC synchronization on 32-bit platforms
On Mon, Jan 11, 2021 at 11:40 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
> 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.
>
> Fixes: c9e6189fb03123a7 ("ntp: Make the RTC synchronization more reliable")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> kernel/time/ntp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
> index 7404d38315276a96..54d52fab201d283e 100644
> --- a/kernel/time/ntp.c
> +++ b/kernel/time/ntp.c
> @@ -498,7 +498,7 @@ int second_overflow(time64_t secs)
> static void sync_hw_clock(struct work_struct *work);
> static DECLARE_WORK(sync_work, sync_hw_clock);
> static struct hrtimer sync_hrtimer;
> -#define SYNC_PERIOD_NS (11UL * 60 * NSEC_PER_SEC)
> +#define SYNC_PERIOD_NS (11ULL * 60 * NSEC_PER_SEC)
>
> static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
> {

While the line

exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec);

is currently not an issue, it may be wise to change it to

exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);

in case someone wants to experiment with values larger then 4s?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

\
 
 \ /
  Last update: 2021-01-11 11:47    [W:0.048 / U:0.820 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site