diff options
author | David S. Miller <davem@davemloft.net> | 2005-08-23 10:49:54 -0700 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-08-23 10:49:54 -0700 |
commit | d5d283751ef3c05b6766501a46800cbee84959d6 (patch) | |
tree | c8de7a2dbd69efb233f1b051bdfceed7eded379a /net/ipv4/tcp_ipv4.c | |
parent | 89ebd197eb2cd31d6187db344d5117064e19fdde (diff) | |
download | linux-3.10-d5d283751ef3c05b6766501a46800cbee84959d6.tar.gz linux-3.10-d5d283751ef3c05b6766501a46800cbee84959d6.tar.bz2 linux-3.10-d5d283751ef3c05b6766501a46800cbee84959d6.zip |
[TCP]: Document non-trivial locking path in tcp_v{4,6}_get_port().
This trips up a lot of folks reading this code.
Put an unlikely() around the port-exhaustion test
for good measure.
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/tcp_ipv4.c')
-rw-r--r-- | net/ipv4/tcp_ipv4.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 5d91213d34c..67c670886c1 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -242,9 +242,14 @@ static int tcp_v4_get_port(struct sock *sk, unsigned short snum) tcp_port_rover = rover; spin_unlock(&tcp_portalloc_lock); - /* Exhausted local port range during search? */ + /* Exhausted local port range during search? It is not + * possible for us to be holding one of the bind hash + * locks if this test triggers, because if 'remaining' + * drops to zero, we broke out of the do/while loop at + * the top level, not from the 'break;' statement. + */ ret = 1; - if (remaining <= 0) + if (unlikely(remaining <= 0)) goto fail; /* OK, here is the one we will use. HEAD is |