Skip to content

Commit ce4c253

Browse files
arndbAl Viro
authored andcommitted
alpha: osf_sys.c: use timespec64 where appropriate
Some of the syscall helper functions (do_utimes, poll_select_set_timeout, core_sys_select) have changed over the past year or two to use 'timespec64' pointers rather than 'timespec'. This was fine on alpha, since 64-bit architectures treat the two as the same type. However, I'd like to change that behavior and make 'timespec64' a proper type of its own even on 64-bit architectures, and that will introduce harmless type mismatch warnings here. Also, I'm trying to kill off the do_gettimeofday() helper in favor of ktime_get() and related interfaces throughout the kernel. This changes the get_tv32/put_tv32 helper functions to also take a timespec64 argument rather than timeval, which allows us to simplify some of the syscall helpers a bit and avoid the type warnings. For the moment, wait4 and adjtimex are still better off with the old behavior, so I'm adding a special put_tv_to_tv32() helper for those. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 47669fb commit ce4c253

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -950,18 +950,27 @@ struct itimerval32
950950
};
951951

952952
static inline long
953-
get_tv32(struct timeval *o, struct timeval32 __user *i)
953+
get_tv32(struct timespec64 *o, struct timeval32 __user *i)
954954
{
955955
struct timeval32 tv;
956956
if (copy_from_user(&tv, i, sizeof(struct timeval32)))
957957
return -EFAULT;
958958
o->tv_sec = tv.tv_sec;
959-
o->tv_usec = tv.tv_usec;
959+
o->tv_nsec = tv.tv_usec * NSEC_PER_USEC;
960960
return 0;
961961
}
962962

963963
static inline long
964-
put_tv32(struct timeval32 __user *o, struct timeval *i)
964+
put_tv32(struct timeval32 __user *o, struct timespec64 *i)
965+
{
966+
return copy_to_user(o, &(struct timeval32){
967+
.tv_sec = i->tv_sec,
968+
.tv_usec = i->tv_nsec / NSEC_PER_USEC},
969+
sizeof(struct timeval32));
970+
}
971+
972+
static inline long
973+
put_tv_to_tv32(struct timeval32 __user *o, struct timeval *i)
965974
{
966975
return copy_to_user(o, &(struct timeval32){
967976
.tv_sec = i->tv_sec,
@@ -1004,9 +1013,10 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
10041013
struct timezone __user *, tz)
10051014
{
10061015
if (tv) {
1007-
struct timeval ktv;
1008-
do_gettimeofday(&ktv);
1009-
if (put_tv32(tv, &ktv))
1016+
struct timespec64 kts;
1017+
1018+
ktime_get_real_ts64(&kts);
1019+
if (put_tv32(tv, &kts))
10101020
return -EFAULT;
10111021
}
10121022
if (tz) {
@@ -1019,22 +1029,19 @@ SYSCALL_DEFINE2(osf_gettimeofday, struct timeval32 __user *, tv,
10191029
SYSCALL_DEFINE2(osf_settimeofday, struct timeval32 __user *, tv,
10201030
struct timezone __user *, tz)
10211031
{
1022-
struct timespec64 kts64;
1023-
struct timespec kts;
1032+
struct timespec64 kts;
10241033
struct timezone ktz;
10251034

10261035
if (tv) {
1027-
if (get_tv32((struct timeval *)&kts, tv))
1036+
if (get_tv32(&kts, tv))
10281037
return -EFAULT;
1029-
kts.tv_nsec *= 1000;
1030-
kts64 = timespec_to_timespec64(kts);
10311038
}
10321039
if (tz) {
10331040
if (copy_from_user(&ktz, tz, sizeof(*tz)))
10341041
return -EFAULT;
10351042
}
10361043

1037-
return do_sys_settimeofday64(tv ? &kts64 : NULL, tz ? &ktz : NULL);
1044+
return do_sys_settimeofday64(tv ? &kts : NULL, tz ? &ktz : NULL);
10381045
}
10391046

10401047
asmlinkage long sys_ni_posix_timers(void);
@@ -1083,22 +1090,16 @@ SYSCALL_DEFINE3(osf_setitimer, int, which, struct itimerval32 __user *, in,
10831090
SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
10841091
struct timeval32 __user *, tvs)
10851092
{
1086-
struct timespec tv[2];
1093+
struct timespec64 tv[2];
10871094

10881095
if (tvs) {
1089-
struct timeval ktvs[2];
1090-
if (get_tv32(&ktvs[0], &tvs[0]) ||
1091-
get_tv32(&ktvs[1], &tvs[1]))
1096+
if (get_tv32(&tv[0], &tvs[0]) ||
1097+
get_tv32(&tv[1], &tvs[1]))
10921098
return -EFAULT;
10931099

1094-
if (ktvs[0].tv_usec < 0 || ktvs[0].tv_usec >= 1000000 ||
1095-
ktvs[1].tv_usec < 0 || ktvs[1].tv_usec >= 1000000)
1100+
if (tv[0].tv_nsec < 0 || tv[0].tv_nsec >= 1000000000 ||
1101+
tv[1].tv_nsec < 0 || tv[1].tv_nsec >= 1000000000)
10961102
return -EINVAL;
1097-
1098-
tv[0].tv_sec = ktvs[0].tv_sec;
1099-
tv[0].tv_nsec = 1000 * ktvs[0].tv_usec;
1100-
tv[1].tv_sec = ktvs[1].tv_sec;
1101-
tv[1].tv_nsec = 1000 * ktvs[1].tv_usec;
11021103
}
11031104

11041105
return do_utimes(AT_FDCWD, filename, tvs ? tv : NULL, 0);
@@ -1107,19 +1108,18 @@ SYSCALL_DEFINE2(osf_utimes, const char __user *, filename,
11071108
SYSCALL_DEFINE5(osf_select, int, n, fd_set __user *, inp, fd_set __user *, outp,
11081109
fd_set __user *, exp, struct timeval32 __user *, tvp)
11091110
{
1110-
struct timespec end_time, *to = NULL;
1111+
struct timespec64 end_time, *to = NULL;
11111112
if (tvp) {
1112-
struct timeval tv;
1113+
struct timespec64 tv;
11131114
to = &end_time;
11141115

11151116
if (get_tv32(&tv, tvp))
11161117
return -EFAULT;
11171118

1118-
if (tv.tv_sec < 0 || tv.tv_usec < 0)
1119+
if (tv.tv_sec < 0 || tv.tv_nsec < 0)
11191120
return -EINVAL;
11201121

1121-
if (poll_select_set_timeout(to, tv.tv_sec,
1122-
tv.tv_usec * NSEC_PER_USEC))
1122+
if (poll_select_set_timeout(to, tv.tv_sec, tv.tv_nsec))
11231123
return -EINVAL;
11241124

11251125
}
@@ -1192,9 +1192,9 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
11921192
return -EFAULT;
11931193
if (!ur)
11941194
return err;
1195-
if (put_tv32(&ur->ru_utime, &r.ru_utime))
1195+
if (put_tv_to_tv32(&ur->ru_utime, &r.ru_utime))
11961196
return -EFAULT;
1197-
if (put_tv32(&ur->ru_stime, &r.ru_stime))
1197+
if (put_tv_to_tv32(&ur->ru_stime, &r.ru_stime))
11981198
return -EFAULT;
11991199
if (copy_to_user(&ur->ru_maxrss, &r.ru_maxrss,
12001200
sizeof(struct rusage32) - offsetof(struct rusage32, ru_maxrss)))
@@ -1210,18 +1210,18 @@ SYSCALL_DEFINE4(osf_wait4, pid_t, pid, int __user *, ustatus, int, options,
12101210
SYSCALL_DEFINE2(osf_usleep_thread, struct timeval32 __user *, sleep,
12111211
struct timeval32 __user *, remain)
12121212
{
1213-
struct timeval tmp;
1213+
struct timespec64 tmp;
12141214
unsigned long ticks;
12151215

12161216
if (get_tv32(&tmp, sleep))
12171217
goto fault;
12181218

1219-
ticks = timeval_to_jiffies(&tmp);
1219+
ticks = timespec64_to_jiffies(&tmp);
12201220

12211221
ticks = schedule_timeout_interruptible(ticks);
12221222

12231223
if (remain) {
1224-
jiffies_to_timeval(ticks, &tmp);
1224+
jiffies_to_timespec64(ticks, &tmp);
12251225
if (put_tv32(remain, &tmp))
12261226
goto fault;
12271227
}
@@ -1280,7 +1280,7 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
12801280
if (copy_to_user(txc_p, &txc, offsetof(struct timex32, time)) ||
12811281
(copy_to_user(&txc_p->tick, &txc.tick, sizeof(struct timex32) -
12821282
offsetof(struct timex32, tick))) ||
1283-
(put_tv32(&txc_p->time, &txc.time)))
1283+
(put_tv_to_tv32(&txc_p->time, &txc.time)))
12841284
return -EFAULT;
12851285

12861286
return ret;

0 commit comments

Comments
 (0)