diff options
author | Eric Dumazet <edumazet@google.com> | 2012-04-26 16:07:59 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-04-27 02:14:21 -0400 |
commit | 82981930125abfd39d7c8378a9cfdf5e1be2002b (patch) | |
tree | 1c5ee5b39af1f39cca3f598beb4e187ae96da685 /net/core | |
parent | c60f6aa8acfd93f4550c7d5eb03351d4cbd1460d (diff) |
net: cleanups in sock_setsockopt()
Use min_t()/max_t() macros, reformat two comments, use !!test_bit() to
match !!sock_flag()
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/sock.c | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index 0431aaf7473a..10605d2ec860 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -577,23 +577,15 @@ int sock_setsockopt(struct socket *sock, int level, int optname, | |||
577 | break; | 577 | break; |
578 | case SO_SNDBUF: | 578 | case SO_SNDBUF: |
579 | /* Don't error on this BSD doesn't and if you think | 579 | /* Don't error on this BSD doesn't and if you think |
580 | about it this is right. Otherwise apps have to | 580 | * about it this is right. Otherwise apps have to |
581 | play 'guess the biggest size' games. RCVBUF/SNDBUF | 581 | * play 'guess the biggest size' games. RCVBUF/SNDBUF |
582 | are treated in BSD as hints */ | 582 | * are treated in BSD as hints |
583 | 583 | */ | |
584 | if (val > sysctl_wmem_max) | 584 | val = min_t(u32, val, sysctl_wmem_max); |
585 | val = sysctl_wmem_max; | ||
586 | set_sndbuf: | 585 | set_sndbuf: |
587 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; | 586 | sk->sk_userlocks |= SOCK_SNDBUF_LOCK; |
588 | if ((val * 2) < SOCK_MIN_SNDBUF) | 587 | sk->sk_sndbuf = max_t(u32, val * 2, SOCK_MIN_SNDBUF); |
589 | sk->sk_sndbuf = SOCK_MIN_SNDBUF; | 588 | /* Wake up sending tasks if we upped the value. */ |
590 | else | ||
591 | sk->sk_sndbuf = val * 2; | ||
592 | |||
593 | /* | ||
594 | * Wake up sending tasks if we | ||
595 | * upped the value. | ||
596 | */ | ||
597 | sk->sk_write_space(sk); | 589 | sk->sk_write_space(sk); |
598 | break; | 590 | break; |
599 | 591 | ||
@@ -606,12 +598,11 @@ set_sndbuf: | |||
606 | 598 | ||
607 | case SO_RCVBUF: | 599 | case SO_RCVBUF: |
608 | /* Don't error on this BSD doesn't and if you think | 600 | /* Don't error on this BSD doesn't and if you think |
609 | about it this is right. Otherwise apps have to | 601 | * about it this is right. Otherwise apps have to |
610 | play 'guess the biggest size' games. RCVBUF/SNDBUF | 602 | * play 'guess the biggest size' games. RCVBUF/SNDBUF |
611 | are treated in BSD as hints */ | 603 | * are treated in BSD as hints |
612 | 604 | */ | |
613 | if (val > sysctl_rmem_max) | 605 | val = min_t(u32, val, sysctl_rmem_max); |
614 | val = sysctl_rmem_max; | ||
615 | set_rcvbuf: | 606 | set_rcvbuf: |
616 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; | 607 | sk->sk_userlocks |= SOCK_RCVBUF_LOCK; |
617 | /* | 608 | /* |
@@ -629,10 +620,7 @@ set_rcvbuf: | |||
629 | * returning the value we actually used in getsockopt | 620 | * returning the value we actually used in getsockopt |
630 | * is the most desirable behavior. | 621 | * is the most desirable behavior. |
631 | */ | 622 | */ |
632 | if ((val * 2) < SOCK_MIN_RCVBUF) | 623 | sk->sk_rcvbuf = max_t(u32, val * 2, SOCK_MIN_RCVBUF); |
633 | sk->sk_rcvbuf = SOCK_MIN_RCVBUF; | ||
634 | else | ||
635 | sk->sk_rcvbuf = val * 2; | ||
636 | break; | 624 | break; |
637 | 625 | ||
638 | case SO_RCVBUFFORCE: | 626 | case SO_RCVBUFFORCE: |
@@ -975,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, | |||
975 | break; | 963 | break; |
976 | 964 | ||
977 | case SO_PASSCRED: | 965 | case SO_PASSCRED: |
978 | v.val = test_bit(SOCK_PASSCRED, &sock->flags) ? 1 : 0; | 966 | v.val = !!test_bit(SOCK_PASSCRED, &sock->flags); |
979 | break; | 967 | break; |
980 | 968 | ||
981 | case SO_PEERCRED: | 969 | case SO_PEERCRED: |
@@ -1010,7 +998,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname, | |||
1010 | break; | 998 | break; |
1011 | 999 | ||
1012 | case SO_PASSSEC: | 1000 | case SO_PASSSEC: |
1013 | v.val = test_bit(SOCK_PASSSEC, &sock->flags) ? 1 : 0; | 1001 | v.val = !!test_bit(SOCK_PASSSEC, &sock->flags); |
1014 | break; | 1002 | break; |
1015 | 1003 | ||
1016 | case SO_PEERSEC: | 1004 | case SO_PEERSEC: |