Skip to content

Commit

Permalink
Merge branch 'dev_get_by_index'
Browse files Browse the repository at this point in the history
Ying Xue says:

====================
use appropriate APIs to get interfaces

Under rtnl_lock protection, we should use __dev_get_name/index()
rather than dev_get_name()/index() to find interface handlers
because the former interfaces can help us avoid to change interface
reference counter.

v2 changes:
 - Change return value of nl80211_set_wiphy() to 0 in patch #10
   by johannes's suggestion.
 - Add 'Acked-by' into several patches which were acknowledged by
   corresponding maintainers.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Jan 15, 2014
2 parents 85a5bac + 7f2b856 commit c4ba999
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 187 deletions.
49 changes: 23 additions & 26 deletions drivers/net/bonding/bond_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3213,37 +3213,34 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd
if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
return -EPERM;

slave_dev = dev_get_by_name(net, ifr->ifr_slave);
slave_dev = __dev_get_by_name(net, ifr->ifr_slave);

pr_debug("slave_dev=%p:\n", slave_dev);

if (!slave_dev)
res = -ENODEV;
else {
pr_debug("slave_dev->name=%s:\n", slave_dev->name);
switch (cmd) {
case BOND_ENSLAVE_OLD:
case SIOCBONDENSLAVE:
res = bond_enslave(bond_dev, slave_dev);
break;
case BOND_RELEASE_OLD:
case SIOCBONDRELEASE:
res = bond_release(bond_dev, slave_dev);
break;
case BOND_SETHWADDR_OLD:
case SIOCBONDSETHWADDR:
bond_set_dev_addr(bond_dev, slave_dev);
res = 0;
break;
case BOND_CHANGE_ACTIVE_OLD:
case SIOCBONDCHANGEACTIVE:
res = bond_option_active_slave_set(bond, slave_dev);
break;
default:
res = -EOPNOTSUPP;
}
return -ENODEV;

dev_put(slave_dev);
pr_debug("slave_dev->name=%s:\n", slave_dev->name);
switch (cmd) {
case BOND_ENSLAVE_OLD:
case SIOCBONDENSLAVE:
res = bond_enslave(bond_dev, slave_dev);
break;
case BOND_RELEASE_OLD:
case SIOCBONDRELEASE:
res = bond_release(bond_dev, slave_dev);
break;
case BOND_SETHWADDR_OLD:
case SIOCBONDSETHWADDR:
bond_set_dev_addr(bond_dev, slave_dev);
res = 0;
break;
case BOND_CHANGE_ACTIVE_OLD:
case SIOCBONDCHANGEACTIVE:
res = bond_option_active_slave_set(bond, slave_dev);
break;
default:
res = -EOPNOTSUPP;
}

return res;
Expand Down
95 changes: 42 additions & 53 deletions drivers/net/eql.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ static int __eql_insert_slave(slave_queue_t *queue, slave_t *slave)
if (duplicate_slave)
eql_kill_one_slave(queue, duplicate_slave);

dev_hold(slave->dev);
list_add(&slave->list, &queue->all_slaves);
queue->num_slaves++;
slave->dev->flags |= IFF_SLAVE;
Expand All @@ -413,39 +414,35 @@ static int eql_enslave(struct net_device *master_dev, slaving_request_t __user *
if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
return -EFAULT;

slave_dev = dev_get_by_name(&init_net, srq.slave_name);
if (slave_dev) {
if ((master_dev->flags & IFF_UP) == IFF_UP) {
/* slave is not a master & not already a slave: */
if (!eql_is_master(slave_dev) &&
!eql_is_slave(slave_dev)) {
slave_t *s = kmalloc(sizeof(*s), GFP_KERNEL);
equalizer_t *eql = netdev_priv(master_dev);
int ret;

if (!s) {
dev_put(slave_dev);
return -ENOMEM;
}

memset(s, 0, sizeof(*s));
s->dev = slave_dev;
s->priority = srq.priority;
s->priority_bps = srq.priority;
s->priority_Bps = srq.priority / 8;

spin_lock_bh(&eql->queue.lock);
ret = __eql_insert_slave(&eql->queue, s);
if (ret) {
dev_put(slave_dev);
kfree(s);
}
spin_unlock_bh(&eql->queue.lock);

return ret;
}
slave_dev = __dev_get_by_name(&init_net, srq.slave_name);
if (!slave_dev)
return -ENODEV;

if ((master_dev->flags & IFF_UP) == IFF_UP) {
/* slave is not a master & not already a slave: */
if (!eql_is_master(slave_dev) && !eql_is_slave(slave_dev)) {
slave_t *s = kmalloc(sizeof(*s), GFP_KERNEL);
equalizer_t *eql = netdev_priv(master_dev);
int ret;

if (!s)
return -ENOMEM;

memset(s, 0, sizeof(*s));
s->dev = slave_dev;
s->priority = srq.priority;
s->priority_bps = srq.priority;
s->priority_Bps = srq.priority / 8;

spin_lock_bh(&eql->queue.lock);
ret = __eql_insert_slave(&eql->queue, s);
if (ret)
kfree(s);

spin_unlock_bh(&eql->queue.lock);

return ret;
}
dev_put(slave_dev);
}

return -EINVAL;
Expand All @@ -461,24 +458,20 @@ static int eql_emancipate(struct net_device *master_dev, slaving_request_t __use
if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
return -EFAULT;

slave_dev = dev_get_by_name(&init_net, srq.slave_name);
ret = -EINVAL;
if (slave_dev) {
spin_lock_bh(&eql->queue.lock);

if (eql_is_slave(slave_dev)) {
slave_t *slave = __eql_find_slave_dev(&eql->queue,
slave_dev);
slave_dev = __dev_get_by_name(&init_net, srq.slave_name);
if (!slave_dev)
return -ENODEV;

if (slave) {
eql_kill_one_slave(&eql->queue, slave);
ret = 0;
}
ret = -EINVAL;
spin_lock_bh(&eql->queue.lock);
if (eql_is_slave(slave_dev)) {
slave_t *slave = __eql_find_slave_dev(&eql->queue, slave_dev);
if (slave) {
eql_kill_one_slave(&eql->queue, slave);
ret = 0;
}
dev_put(slave_dev);

spin_unlock_bh(&eql->queue.lock);
}
spin_unlock_bh(&eql->queue.lock);

return ret;
}
Expand All @@ -494,7 +487,7 @@ static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
return -EFAULT;

slave_dev = dev_get_by_name(&init_net, sc.slave_name);
slave_dev = __dev_get_by_name(&init_net, sc.slave_name);
if (!slave_dev)
return -ENODEV;

Expand All @@ -510,8 +503,6 @@ static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
}
spin_unlock_bh(&eql->queue.lock);

dev_put(slave_dev);

if (!ret && copy_to_user(scp, &sc, sizeof (slave_config_t)))
ret = -EFAULT;

Expand All @@ -529,7 +520,7 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
return -EFAULT;

slave_dev = dev_get_by_name(&init_net, sc.slave_name);
slave_dev = __dev_get_by_name(&init_net, sc.slave_name);
if (!slave_dev)
return -ENODEV;

Expand All @@ -548,8 +539,6 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp)
}
spin_unlock_bh(&eql->queue.lock);

dev_put(slave_dev);

return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,9 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32))
return -EINVAL;
*ifindex = nla_get_u32(tb[NDA_IFINDEX]);
tdev = dev_get_by_index(net, *ifindex);
tdev = __dev_get_by_index(net, *ifindex);
if (!tdev)
return -EADDRNOTAVAIL;
dev_put(tdev);
} else {
*ifindex = 0;
}
Expand Down
15 changes: 7 additions & 8 deletions drivers/staging/cxt1e1/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@ do_del_chan (struct net_device *musycc_dev, void *data)
if (cp.channum > 999)
return -EINVAL;
snprintf (buf, sizeof(buf), CHANNAME "%d", cp.channum);
if (!(dev = dev_get_by_name (&init_net, buf)))
return -ENOENT;
dev_put (dev);
dev = __dev_get_by_name(&init_net, buf);
if (!dev)
return -ENODEV;
ret = do_deluser (dev, 1);
if (ret)
return ret;
Expand All @@ -792,19 +792,18 @@ do_reset (struct net_device *musycc_dev, void *data)
char buf[sizeof (CHANNAME) + 3];

sprintf (buf, CHANNAME "%d", i);
if (!(ndev = dev_get_by_name(&init_net, buf)))
continue;
ndev = __dev_get_by_name(&init_net, buf);
if (!ndev)
continue;
priv = dev_to_hdlc (ndev)->priv;

if ((unsigned long) (priv->ci) ==
(unsigned long) (netdev_priv(musycc_dev)))
{
ndev->flags &= ~IFF_UP;
dev_put (ndev);
netif_stop_queue (ndev);
do_deluser (ndev, 1);
} else
dev_put (ndev);
}
}
return 0;
}
Expand Down
4 changes: 1 addition & 3 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,13 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
return false;

/* recurse over the parent device */
parent_dev = dev_get_by_index(&init_net, net_dev->iflink);
parent_dev = __dev_get_by_index(&init_net, net_dev->iflink);
/* if we got a NULL parent_dev there is something broken.. */
if (WARN(!parent_dev, "Cannot find parent device"))
return false;

ret = batadv_is_on_batman_iface(parent_dev);

if (parent_dev)
dev_put(parent_dev);
return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions net/caif/chnl_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ static int chnl_net_open(struct net_device *dev)
goto error;
}

lldev = dev_get_by_index(dev_net(dev), llifindex);
lldev = __dev_get_by_index(dev_net(dev), llifindex);

if (lldev == NULL) {
pr_debug("no interface?\n");
Expand All @@ -307,7 +307,6 @@ static int chnl_net_open(struct net_device *dev)
mtu = min_t(int, dev->mtu, lldev->mtu - (headroom + tailroom));
mtu = min_t(int, GPRS_PDP_MTU, mtu);
dev_set_mtu(dev, mtu);
dev_put(lldev);

if (mtu < 100) {
pr_warn("CAIF Interface MTU too small (%d)\n", mtu);
Expand Down
15 changes: 5 additions & 10 deletions net/can/gw.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,21 +839,21 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
if (!gwj->ccgw.src_idx || !gwj->ccgw.dst_idx)
goto out;

gwj->src.dev = dev_get_by_index(&init_net, gwj->ccgw.src_idx);
gwj->src.dev = __dev_get_by_index(&init_net, gwj->ccgw.src_idx);

if (!gwj->src.dev)
goto out;

if (gwj->src.dev->type != ARPHRD_CAN)
goto put_src_out;
goto out;

gwj->dst.dev = dev_get_by_index(&init_net, gwj->ccgw.dst_idx);
gwj->dst.dev = __dev_get_by_index(&init_net, gwj->ccgw.dst_idx);

if (!gwj->dst.dev)
goto put_src_out;
goto out;

if (gwj->dst.dev->type != ARPHRD_CAN)
goto put_src_dst_out;
goto out;

gwj->limit_hops = limhops;

Expand All @@ -862,11 +862,6 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
err = cgw_register_filter(gwj);
if (!err)
hlist_add_head_rcu(&gwj->list, &cgw_list);

put_src_dst_out:
dev_put(gwj->dst.dev);
put_src_out:
dev_put(gwj->src.dev);
out:
if (err)
kmem_cache_free(cgw_cache, gwj);
Expand Down
15 changes: 5 additions & 10 deletions net/dcb/dcbnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1688,21 +1688,17 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh)
if (!tb[DCB_ATTR_IFNAME])
return -EINVAL;

netdev = dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME]));
netdev = __dev_get_by_name(net, nla_data(tb[DCB_ATTR_IFNAME]));
if (!netdev)
return -ENODEV;

if (!netdev->dcbnl_ops) {
ret = -EOPNOTSUPP;
goto out;
}
if (!netdev->dcbnl_ops)
return -EOPNOTSUPP;

reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq,
nlh->nlmsg_flags, &reply_nlh);
if (!reply_skb) {
ret = -ENOBUFS;
goto out;
}
if (!reply_skb)
return -ENOBUFS;

ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb);
if (ret < 0) {
Expand All @@ -1714,7 +1710,6 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh)

ret = rtnl_unicast(reply_skb, net, portid);
out:
dev_put(netdev);
return ret;
}

Expand Down
10 changes: 2 additions & 8 deletions net/decnet/dn_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,12 +1666,8 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)

if (fld.flowidn_iif) {
struct net_device *dev;
if ((dev = dev_get_by_index(&init_net, fld.flowidn_iif)) == NULL) {
kfree_skb(skb);
return -ENODEV;
}
if (!dev->dn_ptr) {
dev_put(dev);
dev = __dev_get_by_index(&init_net, fld.flowidn_iif);
if (!dev || !dev->dn_ptr) {
kfree_skb(skb);
return -ENODEV;
}
Expand All @@ -1693,8 +1689,6 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
err = dn_route_output_key((struct dst_entry **)&rt, &fld, 0);
}

if (skb->dev)
dev_put(skb->dev);
skb->dev = NULL;
if (err)
goto out_free;
Expand Down
Loading

0 comments on commit c4ba999

Please sign in to comment.