Skip to content

Commit 33e2641

Browse files
committed
y2038: make do_gettimeofday() and get_seconds() inline
get_seconds() and do_gettimeofday() are only used by a few modules now any more (waiting for the respective patches to get accepted), and they are among the last holdouts of code that is not y2038 safe in the core kernel. Move the implementation into the timekeeping32.h header to clean up the core kernel and isolate the old interfaces further. Signed-off-by: Arnd Bergmann <arnd@arndb.de>
1 parent 9765164 commit 33e2641

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

include/linux/timekeeping32.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@
66
* over time so we can remove the file here.
77
*/
88

9-
extern void do_gettimeofday(struct timeval *tv);
10-
unsigned long get_seconds(void);
9+
static inline void do_gettimeofday(struct timeval *tv)
10+
{
11+
struct timespec64 now;
12+
13+
ktime_get_real_ts64(&now);
14+
tv->tv_sec = now.tv_sec;
15+
tv->tv_usec = now.tv_nsec/1000;
16+
}
17+
18+
static inline unsigned long get_seconds(void)
19+
{
20+
return ktime_get_real_seconds();
21+
}
1122

1223
static inline void getnstimeofday(struct timespec *ts)
1324
{

kernel/time/time.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,11 @@ SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv,
144144
struct timezone __user *, tz)
145145
{
146146
if (likely(tv != NULL)) {
147-
struct timeval ktv;
148-
do_gettimeofday(&ktv);
149-
if (copy_to_user(tv, &ktv, sizeof(ktv)))
147+
struct timespec64 ts;
148+
149+
ktime_get_real_ts64(&ts);
150+
if (put_user(ts.tv_sec, &tv->tv_sec) ||
151+
put_user(ts.tv_nsec / 1000, &tv->tv_usec))
150152
return -EFAULT;
151153
}
152154
if (unlikely(tz != NULL)) {
@@ -227,10 +229,11 @@ COMPAT_SYSCALL_DEFINE2(gettimeofday, struct compat_timeval __user *, tv,
227229
struct timezone __user *, tz)
228230
{
229231
if (tv) {
230-
struct timeval ktv;
232+
struct timespec64 ts;
231233

232-
do_gettimeofday(&ktv);
233-
if (compat_put_timeval(&ktv, tv))
234+
ktime_get_real_ts64(&ts);
235+
if (put_user(ts.tv_sec, &tv->tv_sec) ||
236+
put_user(ts.tv_nsec / 1000, &tv->tv_usec))
234237
return -EFAULT;
235238
}
236239
if (tz) {

kernel/time/timekeeping.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,22 +1211,6 @@ int get_device_system_crosststamp(int (*get_time_fn)
12111211
}
12121212
EXPORT_SYMBOL_GPL(get_device_system_crosststamp);
12131213

1214-
/**
1215-
* do_gettimeofday - Returns the time of day in a timeval
1216-
* @tv: pointer to the timeval to be set
1217-
*
1218-
* NOTE: Users should be converted to using getnstimeofday()
1219-
*/
1220-
void do_gettimeofday(struct timeval *tv)
1221-
{
1222-
struct timespec64 now;
1223-
1224-
getnstimeofday64(&now);
1225-
tv->tv_sec = now.tv_sec;
1226-
tv->tv_usec = now.tv_nsec/1000;
1227-
}
1228-
EXPORT_SYMBOL(do_gettimeofday);
1229-
12301214
/**
12311215
* do_settimeofday64 - Sets the time of day.
12321216
* @ts: pointer to the timespec64 variable containing the new time
@@ -2174,14 +2158,6 @@ void getboottime64(struct timespec64 *ts)
21742158
}
21752159
EXPORT_SYMBOL_GPL(getboottime64);
21762160

2177-
unsigned long get_seconds(void)
2178-
{
2179-
struct timekeeper *tk = &tk_core.timekeeper;
2180-
2181-
return tk->xtime_sec;
2182-
}
2183-
EXPORT_SYMBOL(get_seconds);
2184-
21852161
void ktime_get_coarse_real_ts64(struct timespec64 *ts)
21862162
{
21872163
struct timekeeper *tk = &tk_core.timekeeper;

0 commit comments

Comments
 (0)