mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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: c9e6189fb0 ("ntp: Make the RTC synchronization more reliable")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/r/20210111103956.290378-1-geert+renesas@glider.be
			
			
This commit is contained in:
		
							parent
							
								
									aba428a0c6
								
							
						
					
					
						commit
						e3fab2f3de
					
				
					 1 changed files with 2 additions and 2 deletions
				
			
		| 
						 | 
					@ -498,7 +498,7 @@ int second_overflow(time64_t secs)
 | 
				
			||||||
static void sync_hw_clock(struct work_struct *work);
 | 
					static void sync_hw_clock(struct work_struct *work);
 | 
				
			||||||
static DECLARE_WORK(sync_work, sync_hw_clock);
 | 
					static DECLARE_WORK(sync_work, sync_hw_clock);
 | 
				
			||||||
static struct hrtimer sync_hrtimer;
 | 
					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)
 | 
					static enum hrtimer_restart sync_timer_callback(struct hrtimer *timer)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -512,7 +512,7 @@ static void sched_sync_hw_clock(unsigned long offset_nsec, bool retry)
 | 
				
			||||||
	ktime_t exp = ktime_set(ktime_get_real_seconds(), 0);
 | 
						ktime_t exp = ktime_set(ktime_get_real_seconds(), 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (retry)
 | 
						if (retry)
 | 
				
			||||||
		exp = ktime_add_ns(exp, 2 * NSEC_PER_SEC - offset_nsec);
 | 
							exp = ktime_add_ns(exp, 2ULL * NSEC_PER_SEC - offset_nsec);
 | 
				
			||||||
	else
 | 
						else
 | 
				
			||||||
		exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec);
 | 
							exp = ktime_add_ns(exp, SYNC_PERIOD_NS - offset_nsec);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue