Commit 723b4610 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

net: udp_unhash() can test if sk is hashed

Impact: Optimization

Like done in inet_unhash(), we can avoid taking a chain lock if
socket is not hashed in udp_unhash()

Triggered by close(socket(AF_INET, SOCK_DGRAM, 0));
Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5bc0b3bf
...@@ -970,6 +970,7 @@ int udp_disconnect(struct sock *sk, int flags) ...@@ -970,6 +970,7 @@ int udp_disconnect(struct sock *sk, int flags)
void udp_lib_unhash(struct sock *sk) void udp_lib_unhash(struct sock *sk)
{ {
if (sk_hashed(sk)) {
struct udp_table *udptable = sk->sk_prot->h.udp_table; struct udp_table *udptable = sk->sk_prot->h.udp_table;
unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash); unsigned int hash = udp_hashfn(sock_net(sk), sk->sk_hash);
struct udp_hslot *hslot = &udptable->hash[hash]; struct udp_hslot *hslot = &udptable->hash[hash];
...@@ -980,6 +981,7 @@ void udp_lib_unhash(struct sock *sk) ...@@ -980,6 +981,7 @@ void udp_lib_unhash(struct sock *sk)
sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1); sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
} }
spin_unlock_bh(&hslot->lock); spin_unlock_bh(&hslot->lock);
}
} }
EXPORT_SYMBOL(udp_lib_unhash); EXPORT_SYMBOL(udp_lib_unhash);
......
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