socket: move compat timeout handling into sock.c
This is a cleanup to prepare for the addition of 64-bit time_t in O_SNDTIMEO/O_RCVTIMEO. The existing compat handler seems unnecessarily complex and error-prone, moving it all into the main setsockopt()/getsockopt() implementation requires half as much code and is easier to extend. 32-bit user space can now use old_timeval32 on both 32-bit and 64-bit machines, while 64-bit code can use __old_kernel_timeval. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com> Acked-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
a9bcfd1d17
commit
fe0c72f3db
@@ -335,14 +335,48 @@ int __sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
|
||||
}
|
||||
EXPORT_SYMBOL(__sk_backlog_rcv);
|
||||
|
||||
static int sock_get_timeout(long timeo, void *optval)
|
||||
{
|
||||
struct __kernel_old_timeval tv;
|
||||
|
||||
if (timeo == MAX_SCHEDULE_TIMEOUT) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 0;
|
||||
} else {
|
||||
tv.tv_sec = timeo / HZ;
|
||||
tv.tv_usec = ((timeo % HZ) * USEC_PER_SEC) / HZ;
|
||||
}
|
||||
|
||||
if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
|
||||
struct old_timeval32 tv32 = { tv.tv_sec, tv.tv_usec };
|
||||
*(struct old_timeval32 *)optval = tv32;
|
||||
return sizeof(tv32);
|
||||
}
|
||||
|
||||
*(struct __kernel_old_timeval *)optval = tv;
|
||||
return sizeof(tv);
|
||||
}
|
||||
|
||||
static int sock_set_timeout(long *timeo_p, char __user *optval, int optlen)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct __kernel_old_timeval tv;
|
||||
|
||||
if (optlen < sizeof(tv))
|
||||
return -EINVAL;
|
||||
if (copy_from_user(&tv, optval, sizeof(tv)))
|
||||
return -EFAULT;
|
||||
if (in_compat_syscall() && !COMPAT_USE_64BIT_TIME) {
|
||||
struct old_timeval32 tv32;
|
||||
|
||||
if (optlen < sizeof(tv32))
|
||||
return -EINVAL;
|
||||
|
||||
if (copy_from_user(&tv32, optval, sizeof(tv32)))
|
||||
return -EFAULT;
|
||||
tv.tv_sec = tv32.tv_sec;
|
||||
tv.tv_usec = tv32.tv_usec;
|
||||
} else {
|
||||
if (optlen < sizeof(tv))
|
||||
return -EINVAL;
|
||||
if (copy_from_user(&tv, optval, sizeof(tv)))
|
||||
return -EFAULT;
|
||||
}
|
||||
if (tv.tv_usec < 0 || tv.tv_usec >= USEC_PER_SEC)
|
||||
return -EDOM;
|
||||
|
||||
@@ -1121,7 +1155,8 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
|
||||
int val;
|
||||
u64 val64;
|
||||
struct linger ling;
|
||||
struct timeval tm;
|
||||
struct old_timeval32 tm32;
|
||||
struct __kernel_old_timeval tm;
|
||||
struct sock_txtime txtime;
|
||||
} v;
|
||||
|
||||
@@ -1222,25 +1257,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
|
||||
break;
|
||||
|
||||
case SO_RCVTIMEO:
|
||||
lv = sizeof(struct timeval);
|
||||
if (sk->sk_rcvtimeo == MAX_SCHEDULE_TIMEOUT) {
|
||||
v.tm.tv_sec = 0;
|
||||
v.tm.tv_usec = 0;
|
||||
} else {
|
||||
v.tm.tv_sec = sk->sk_rcvtimeo / HZ;
|
||||
v.tm.tv_usec = ((sk->sk_rcvtimeo % HZ) * USEC_PER_SEC) / HZ;
|
||||
}
|
||||
lv = sock_get_timeout(sk->sk_rcvtimeo, &v);
|
||||
break;
|
||||
|
||||
case SO_SNDTIMEO:
|
||||
lv = sizeof(struct timeval);
|
||||
if (sk->sk_sndtimeo == MAX_SCHEDULE_TIMEOUT) {
|
||||
v.tm.tv_sec = 0;
|
||||
v.tm.tv_usec = 0;
|
||||
} else {
|
||||
v.tm.tv_sec = sk->sk_sndtimeo / HZ;
|
||||
v.tm.tv_usec = ((sk->sk_sndtimeo % HZ) * USEC_PER_SEC) / HZ;
|
||||
}
|
||||
lv = sock_get_timeout(sk->sk_sndtimeo, &v);
|
||||
break;
|
||||
|
||||
case SO_RCVLOWAT:
|
||||
|
Reference in New Issue
Block a user