Commit 3e21b29f authored by Eric Dumazet's avatar Eric Dumazet Committed by Ben Hutchings

net: cleanups in sock_setsockopt()

commit 82981930 upstream.

Use min_t()/max_t() macros, reformat two comments, use !!test_bit() to
match !!sock_flag()
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 3dd88dcf
...@@ -526,23 +526,15 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -526,23 +526,15 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_SNDBUF: case SO_SNDBUF:
/* Don't error on this BSD doesn't and if you think /* Don't error on this BSD doesn't and if you think
about it this is right. Otherwise apps have to * about it this is right. Otherwise apps have to
play 'guess the biggest size' games. RCVBUF/SNDBUF * play 'guess the biggest size' games. RCVBUF/SNDBUF
are treated in BSD as hints */ * are treated in BSD as hints
*/
if (val > sysctl_wmem_max) val = min_t(u32, val, sysctl_wmem_max);
val = sysctl_wmem_max;
set_sndbuf: set_sndbuf:
sk->sk_userlocks |= SOCK_SNDBUF_LOCK; sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
if ((val * 2) < SOCK_MIN_SNDBUF) sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF);
sk->sk_sndbuf = SOCK_MIN_SNDBUF; /* Wake up sending tasks if we upped the value. */
else
sk->sk_sndbuf = val * 2;
/*
* Wake up sending tasks if we
* upped the value.
*/
sk->sk_write_space(sk); sk->sk_write_space(sk);
break; break;
...@@ -555,12 +547,11 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -555,12 +547,11 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_RCVBUF: case SO_RCVBUF:
/* Don't error on this BSD doesn't and if you think /* Don't error on this BSD doesn't and if you think
about it this is right. Otherwise apps have to * about it this is right. Otherwise apps have to
play 'guess the biggest size' games. RCVBUF/SNDBUF * play 'guess the biggest size' games. RCVBUF/SNDBUF
are treated in BSD as hints */ * are treated in BSD as hints
*/
if (val > sysctl_rmem_max) val = min_t(u32, val, sysctl_rmem_max);
val = sysctl_rmem_max;
set_rcvbuf: set_rcvbuf:
sk->sk_userlocks |= SOCK_RCVBUF_LOCK; sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
/* /*
...@@ -578,10 +569,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -578,10 +569,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
* returning the value we actually used in getsockopt * returning the value we actually used in getsockopt
* is the most desirable behavior. * is the most desirable behavior.
*/ */
if ((val * 2) < SOCK_MIN_RCVBUF) sk->sk_rcvbuf = max_t(u32, val * 2, SOCK_MIN_RCVBUF);
sk->sk_rcvbuf = SOCK_MIN_RCVBUF;
else
sk->sk_rcvbuf = val * 2;
break; break;
case SO_RCVBUFFORCE: case SO_RCVBUFFORCE:
...@@ -923,7 +911,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, ...@@ -923,7 +911,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_PASSCRED: case SO_PASSCRED:
v.val = test_bit(SOCK_PASSCRED, &sock->flags) ? 1 : 0; v.val = !!test_bit(SOCK_PASSCRED, &sock->flags);
break; break;
case SO_PEERCRED: case SO_PEERCRED:
...@@ -958,7 +946,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, ...@@ -958,7 +946,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
break; break;
case SO_PASSSEC: case SO_PASSSEC:
v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0; v.val = !!test_bit(SOCK_PASSSEC, &sock->flags);
break; break;
case SO_PEERSEC: case SO_PEERSEC:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment