Skip to content

Commit

Permalink
net: dev_getfirstbyhwtype() optimization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Eric Dumazet authored and David S. Miller committed Mar 22, 2010
1 parent ec733b1 commit 99fe3c3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 99fe3c3

Please sign in to comment.