net: dev_getfirstbyhwtype() optimization
authorEric Dumazet <eric.dumazet@gmail.com>
Thu, 18 Mar 2010 11:27:25 +0000 (11:27 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Mar 2010 03:33:36 +0000 (20:33 -0700)
Use RCU to avoid RTNL use in dev_getfirstbyhwtype()

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

index 2d01f18f303a0dc985028b8bcc657ab1734d26de..a03aab45e84faa04eac4d12124eb5e5d5ed48d91 100644 (file)
@@ -772,14 +772,17 @@ EXPORT_SYMBOL(__dev_getfirstbyhwtype);
 
 struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
 {
-       struct net_device *dev;
+       struct net_device *dev, *ret = NULL;
 
-       rtnl_lock();
-       dev = __dev_getfirstbyhwtype(net, type);
-       if (dev)
-               dev_hold(dev);
-       rtnl_unlock();
-       return dev;
+       rcu_read_lock();
+       for_each_netdev_rcu(net, dev)
+               if (dev->type == type) {
+                       dev_hold(dev);
+                       ret = dev;
+                       break;
+               }
+       rcu_read_unlock();
+       return ret;
 }
 EXPORT_SYMBOL(dev_getfirstbyhwtype);