net: sock_bindtodevice() RCU-ification
authorEric Dumazet <eric.dumazet@gmail.com>
Fri, 6 Nov 2009 05:03:39 +0000 (21:03 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 6 Nov 2009 06:34:24 +0000 (22:34 -0800)
Avoid dev_hold()/dev_put() in sock_bindtodevice()

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/sock.c

index 5a51512f638a9259a6da4caa126889166a8dfb51..38820eaecd4347291bf434735e89c93600b0f3c6 100644 (file)
@@ -420,14 +420,16 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
        if (devname[0] == '\0') {
                index = 0;
        } else {
-               struct net_device *dev = dev_get_by_name(net, devname);
+               struct net_device *dev;
 
+               rcu_read_lock();
+               dev = dev_get_by_name_rcu(net, devname);
+               if (dev)
+                       index = dev->ifindex;
+               rcu_read_unlock();
                ret = -ENODEV;
                if (!dev)
                        goto out;
-
-               index = dev->ifindex;
-               dev_put(dev);
        }
 
        lock_sock(sk);