Skip to content

Commit ade1bdf

Browse files
arndbjohnstultz-work
authored andcommitted
ntp/pps: use y2038 safe types in pps_event_time
The pps_event_time uses two 'timespec' structures internally, which suffer from the y2038 problem. The uses of this structure are fairly self-contained in the pps code, so this replaces them all at once. Unfortunately, this includes the sfc ethernet driver aside from the pps subsystem, so we change that one as well. Both touch the same data structure, and there probably is no good way to split the patch into smaller units. Acked-by: Richard Cochran <richardcochran@gmail.com> Acked-by: David S. Miller <davem@davemloft.net> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 5fd96c4 commit ade1bdf

4 files changed

Lines changed: 19 additions & 26 deletions

File tree

‎drivers/net/ethernet/sfc/ptp.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -646,28 +646,28 @@ static void efx_ptp_send_times(struct efx_nic *efx,
646646
struct pps_event_time *last_time)
647647
{
648648
struct pps_event_time now;
649-
struct timespec limit;
649+
struct timespec64 limit;
650650
struct efx_ptp_data *ptp = efx->ptp_data;
651-
struct timespec start;
651+
struct timespec64 start;
652652
int *mc_running = ptp->start.addr;
653653

654654
pps_get_ts(&now);
655655
start = now.ts_real;
656656
limit = now.ts_real;
657-
timespec_add_ns(&limit, SYNCHRONISE_PERIOD_NS);
657+
timespec64_add_ns(&limit, SYNCHRONISE_PERIOD_NS);
658658

659659
/* Write host time for specified period or until MC is done */
660-
while ((timespec_compare(&now.ts_real, &limit) < 0) &&
660+
while ((timespec64_compare(&now.ts_real, &limit) < 0) &&
661661
ACCESS_ONCE(*mc_running)) {
662-
struct timespec update_time;
662+
struct timespec64 update_time;
663663
unsigned int host_time;
664664

665665
/* Don't update continuously to avoid saturating the PCIe bus */
666666
update_time = now.ts_real;
667-
timespec_add_ns(&update_time, SYNCHRONISATION_GRANULARITY_NS);
667+
timespec64_add_ns(&update_time, SYNCHRONISATION_GRANULARITY_NS);
668668
do {
669669
pps_get_ts(&now);
670-
} while ((timespec_compare(&now.ts_real, &update_time) < 0) &&
670+
} while ((timespec64_compare(&now.ts_real, &update_time) < 0) &&
671671
ACCESS_ONCE(*mc_running));
672672

673673
/* Synchronise NIC with single word of time only */
@@ -723,7 +723,7 @@ efx_ptp_process_times(struct efx_nic *efx, MCDI_DECLARE_STRUCT_PTR(synch_buf),
723723
struct efx_ptp_data *ptp = efx->ptp_data;
724724
u32 last_sec;
725725
u32 start_sec;
726-
struct timespec delta;
726+
struct timespec64 delta;
727727
ktime_t mc_time;
728728

729729
if (number_readings == 0)

‎drivers/pps/kapi.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ void pps_event(struct pps_device *pps, struct pps_event_time *ts, int event,
179179
/* check event type */
180180
BUG_ON((event & (PPS_CAPTUREASSERT | PPS_CAPTURECLEAR)) == 0);
181181

182-
dev_dbg(pps->dev, "PPS event at %ld.%09ld\n",
183-
ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
182+
dev_dbg(pps->dev, "PPS event at %lld.%09ld\n",
183+
(s64)ts->ts_real.tv_sec, ts->ts_real.tv_nsec);
184184

185185
timespec_to_pps_ktime(&ts_real, ts->ts_real);
186186

‎drivers/pps/kc.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,10 @@ void pps_kc_event(struct pps_device *pps, struct pps_event_time *ts,
113113
int event)
114114
{
115115
unsigned long flags;
116-
struct timespec64 real = timespec_to_timespec64(ts->ts_real);
117-
struct timespec64 raw = timespec_to_timespec64(ts->ts_raw);
118116

119117
/* Pass some events to kernel consumer if activated */
120118
spin_lock_irqsave(&pps_kc_hardpps_lock, flags);
121119
if (pps == pps_kc_hardpps_dev && event & pps_kc_hardpps_mode)
122-
hardpps(&real, &raw);
120+
hardpps(&ts->ts_real, &ts->ts_raw);
123121
spin_unlock_irqrestore(&pps_kc_hardpps_lock, flags);
124122
}

‎include/linux/pps_kernel.h‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ struct pps_source_info {
4848

4949
struct pps_event_time {
5050
#ifdef CONFIG_NTP_PPS
51-
struct timespec ts_raw;
51+
struct timespec64 ts_raw;
5252
#endif /* CONFIG_NTP_PPS */
53-
struct timespec ts_real;
53+
struct timespec64 ts_real;
5454
};
5555

5656
/* The main struct */
@@ -105,7 +105,7 @@ extern void pps_event(struct pps_device *pps,
105105
struct pps_device *pps_lookup_dev(void const *cookie);
106106

107107
static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
108-
struct timespec ts)
108+
struct timespec64 ts)
109109
{
110110
kt->sec = ts.tv_sec;
111111
kt->nsec = ts.tv_nsec;
@@ -115,29 +115,24 @@ static inline void timespec_to_pps_ktime(struct pps_ktime *kt,
115115

116116
static inline void pps_get_ts(struct pps_event_time *ts)
117117
{
118-
struct timespec64 raw, real;
119-
120-
ktime_get_raw_and_real_ts64(&raw, &real);
121-
122-
ts->ts_raw = timespec64_to_timespec(raw);
123-
ts->ts_real = timespec64_to_timespec(real);
118+
ktime_get_raw_and_real_ts64(&ts->ts_raw, &ts->ts_real);
124119
}
125120

126121
#else /* CONFIG_NTP_PPS */
127122

128123
static inline void pps_get_ts(struct pps_event_time *ts)
129124
{
130-
getnstimeofday(&ts->ts_real);
125+
ktime_get_real_ts64(&ts->ts_real);
131126
}
132127

133128
#endif /* CONFIG_NTP_PPS */
134129

135130
/* Subtract known time delay from PPS event time(s) */
136-
static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec delta)
131+
static inline void pps_sub_ts(struct pps_event_time *ts, struct timespec64 delta)
137132
{
138-
ts->ts_real = timespec_sub(ts->ts_real, delta);
133+
ts->ts_real = timespec64_sub(ts->ts_real, delta);
139134
#ifdef CONFIG_NTP_PPS
140-
ts->ts_raw = timespec_sub(ts->ts_raw, delta);
135+
ts->ts_raw = timespec64_sub(ts->ts_raw, delta);
141136
#endif
142137
}
143138

0 commit comments

Comments
 (0)