Commit 16ba5e8e authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

ipv6: no more dev_put() in inet6_bind()

Avoids touching device refcount in inet6_bind(), thanks to RCU
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent f1a28eab
...@@ -314,6 +314,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -314,6 +314,7 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
if (addr_type != IPV6_ADDR_ANY) { if (addr_type != IPV6_ADDR_ANY) {
struct net_device *dev = NULL; struct net_device *dev = NULL;
rcu_read_lock();
if (addr_type & IPV6_ADDR_LINKLOCAL) { if (addr_type & IPV6_ADDR_LINKLOCAL) {
if (addr_len >= sizeof(struct sockaddr_in6) && if (addr_len >= sizeof(struct sockaddr_in6) &&
addr->sin6_scope_id) { addr->sin6_scope_id) {
...@@ -326,12 +327,12 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -326,12 +327,12 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
/* Binding to link-local address requires an interface */ /* Binding to link-local address requires an interface */
if (!sk->sk_bound_dev_if) { if (!sk->sk_bound_dev_if) {
err = -EINVAL; err = -EINVAL;
goto out; goto out_unlock;
} }
dev = dev_get_by_index(net, sk->sk_bound_dev_if); dev = dev_get_by_index_rcu(net, sk->sk_bound_dev_if);
if (!dev) { if (!dev) {
err = -ENODEV; err = -ENODEV;
goto out; goto out_unlock;
} }
} }
...@@ -342,14 +343,11 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -342,14 +343,11 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
if (!(addr_type & IPV6_ADDR_MULTICAST)) { if (!(addr_type & IPV6_ADDR_MULTICAST)) {
if (!ipv6_chk_addr(net, &addr->sin6_addr, if (!ipv6_chk_addr(net, &addr->sin6_addr,
dev, 0)) { dev, 0)) {
if (dev)
dev_put(dev);
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto out; goto out_unlock;
} }
} }
if (dev) rcu_read_unlock();
dev_put(dev);
} }
} }
...@@ -381,6 +379,9 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) ...@@ -381,6 +379,9 @@ int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
out: out:
release_sock(sk); release_sock(sk);
return err; return err;
out_unlock:
rcu_read_unlock();
goto out;
} }
EXPORT_SYMBOL(inet6_bind); EXPORT_SYMBOL(inet6_bind);
......
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