Commit c4ba9993 authored by David S. Miller's avatar David S. Miller

Merge branch 'dev_get_by_index'

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 85a5bac9 7f2b8562
...@@ -3213,37 +3213,34 @@ static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd ...@@ -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)) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
return -EPERM; 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); pr_debug("slave_dev=%p:\n", slave_dev);
if (!slave_dev) if (!slave_dev)
res = -ENODEV; return -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;
}
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; return res;
......
...@@ -395,6 +395,7 @@ static int __eql_insert_slave(slave_queue_t *queue, slave_t *slave) ...@@ -395,6 +395,7 @@ static int __eql_insert_slave(slave_queue_t *queue, slave_t *slave)
if (duplicate_slave) if (duplicate_slave)
eql_kill_one_slave(queue, duplicate_slave); eql_kill_one_slave(queue, duplicate_slave);
dev_hold(slave->dev);
list_add(&slave->list, &queue->all_slaves); list_add(&slave->list, &queue->all_slaves);
queue->num_slaves++; queue->num_slaves++;
slave->dev->flags |= IFF_SLAVE; slave->dev->flags |= IFF_SLAVE;
...@@ -413,39 +414,35 @@ static int eql_enslave(struct net_device *master_dev, slaving_request_t __user * ...@@ -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))) if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
return -EFAULT; return -EFAULT;
slave_dev = dev_get_by_name(&init_net, srq.slave_name); slave_dev = __dev_get_by_name(&init_net, srq.slave_name);
if (slave_dev) { if (!slave_dev)
if ((master_dev->flags & IFF_UP) == IFF_UP) { return -ENODEV;
/* slave is not a master & not already a slave: */
if (!eql_is_master(slave_dev) && if ((master_dev->flags & IFF_UP) == IFF_UP) {
!eql_is_slave(slave_dev)) { /* slave is not a master & not already a slave: */
slave_t *s = kmalloc(sizeof(*s), GFP_KERNEL); if (!eql_is_master(slave_dev) && !eql_is_slave(slave_dev)) {
equalizer_t *eql = netdev_priv(master_dev); slave_t *s = kmalloc(sizeof(*s), GFP_KERNEL);
int ret; equalizer_t *eql = netdev_priv(master_dev);
int ret;
if (!s) {
dev_put(slave_dev); if (!s)
return -ENOMEM; return -ENOMEM;
}
memset(s, 0, sizeof(*s));
memset(s, 0, sizeof(*s)); s->dev = slave_dev;
s->dev = slave_dev; s->priority = srq.priority;
s->priority = srq.priority; s->priority_bps = srq.priority;
s->priority_bps = srq.priority; s->priority_Bps = srq.priority / 8;
s->priority_Bps = srq.priority / 8;
spin_lock_bh(&eql->queue.lock);
spin_lock_bh(&eql->queue.lock); ret = __eql_insert_slave(&eql->queue, s);
ret = __eql_insert_slave(&eql->queue, s); if (ret)
if (ret) { kfree(s);
dev_put(slave_dev);
kfree(s); spin_unlock_bh(&eql->queue.lock);
}
spin_unlock_bh(&eql->queue.lock); return ret;
return ret;
}
} }
dev_put(slave_dev);
} }
return -EINVAL; return -EINVAL;
...@@ -461,24 +458,20 @@ static int eql_emancipate(struct net_device *master_dev, slaving_request_t __use ...@@ -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))) if (copy_from_user(&srq, srqp, sizeof (slaving_request_t)))
return -EFAULT; return -EFAULT;
slave_dev = dev_get_by_name(&init_net, srq.slave_name); slave_dev = __dev_get_by_name(&init_net, srq.slave_name);
ret = -EINVAL; if (!slave_dev)
if (slave_dev) { return -ENODEV;
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) { ret = -EINVAL;
eql_kill_one_slave(&eql->queue, slave); spin_lock_bh(&eql->queue.lock);
ret = 0; 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; return ret;
} }
...@@ -494,7 +487,7 @@ static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp) ...@@ -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))) if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
return -EFAULT; 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) if (!slave_dev)
return -ENODEV; return -ENODEV;
...@@ -510,8 +503,6 @@ static int eql_g_slave_cfg(struct net_device *dev, slave_config_t __user *scp) ...@@ -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); spin_unlock_bh(&eql->queue.lock);
dev_put(slave_dev);
if (!ret && copy_to_user(scp, &sc, sizeof (slave_config_t))) if (!ret && copy_to_user(scp, &sc, sizeof (slave_config_t)))
ret = -EFAULT; ret = -EFAULT;
...@@ -529,7 +520,7 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp) ...@@ -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))) if (copy_from_user(&sc, scp, sizeof (slave_config_t)))
return -EFAULT; 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) if (!slave_dev)
return -ENODEV; return -ENODEV;
...@@ -548,8 +539,6 @@ static int eql_s_slave_cfg(struct net_device *dev, slave_config_t __user *scp) ...@@ -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); spin_unlock_bh(&eql->queue.lock);
dev_put(slave_dev);
return ret; return ret;
} }
......
...@@ -741,10 +741,9 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan, ...@@ -741,10 +741,9 @@ static int vxlan_fdb_parse(struct nlattr *tb[], struct vxlan_dev *vxlan,
if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32)) if (nla_len(tb[NDA_IFINDEX]) != sizeof(u32))
return -EINVAL; return -EINVAL;
*ifindex = nla_get_u32(tb[NDA_IFINDEX]); *ifindex = nla_get_u32(tb[NDA_IFINDEX]);
tdev = dev_get_by_index(net, *ifindex); tdev = __dev_get_by_index(net, *ifindex);
if (!tdev) if (!tdev)
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
dev_put(tdev);
} else { } else {
*ifindex = 0; *ifindex = 0;
} }
......
...@@ -770,9 +770,9 @@ do_del_chan (struct net_device *musycc_dev, void *data) ...@@ -770,9 +770,9 @@ do_del_chan (struct net_device *musycc_dev, void *data)
if (cp.channum > 999) if (cp.channum > 999)
return -EINVAL; return -EINVAL;
snprintf (buf, sizeof(buf), CHANNAME "%d", cp.channum); snprintf (buf, sizeof(buf), CHANNAME "%d", cp.channum);
if (!(dev = dev_get_by_name (&init_net, buf))) dev = __dev_get_by_name(&init_net, buf);
return -ENOENT; if (!dev)
dev_put (dev); return -ENODEV;
ret = do_deluser (dev, 1); ret = do_deluser (dev, 1);
if (ret) if (ret)
return ret; return ret;
...@@ -792,19 +792,18 @@ do_reset (struct net_device *musycc_dev, void *data) ...@@ -792,19 +792,18 @@ do_reset (struct net_device *musycc_dev, void *data)
char buf[sizeof (CHANNAME) + 3]; char buf[sizeof (CHANNAME) + 3];
sprintf (buf, CHANNAME "%d", i); sprintf (buf, CHANNAME "%d", i);
if (!(ndev = dev_get_by_name(&init_net, buf))) ndev = __dev_get_by_name(&init_net, buf);
continue; if (!ndev)
continue;
priv = dev_to_hdlc (ndev)->priv; priv = dev_to_hdlc (ndev)->priv;
if ((unsigned long) (priv->ci) == if ((unsigned long) (priv->ci) ==
(unsigned long) (netdev_priv(musycc_dev))) (unsigned long) (netdev_priv(musycc_dev)))
{ {
ndev->flags &= ~IFF_UP; ndev->flags &= ~IFF_UP;
dev_put (ndev);
netif_stop_queue (ndev); netif_stop_queue (ndev);
do_deluser (ndev, 1); do_deluser (ndev, 1);
} else }
dev_put (ndev);
} }
return 0; return 0;
} }
......
...@@ -87,15 +87,13 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) ...@@ -87,15 +87,13 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
return false; return false;
/* recurse over the parent device */ /* 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 we got a NULL parent_dev there is something broken.. */
if (WARN(!parent_dev, "Cannot find parent device")) if (WARN(!parent_dev, "Cannot find parent device"))
return false; return false;
ret = batadv_is_on_batman_iface(parent_dev); ret = batadv_is_on_batman_iface(parent_dev);
if (parent_dev)
dev_put(parent_dev);
return ret; return ret;
} }
......
...@@ -285,7 +285,7 @@ static int chnl_net_open(struct net_device *dev) ...@@ -285,7 +285,7 @@ static int chnl_net_open(struct net_device *dev)
goto error; goto error;
} }
lldev = dev_get_by_index(dev_net(dev), llifindex); lldev = __dev_get_by_index(dev_net(dev), llifindex);
if (lldev == NULL) { if (lldev == NULL) {
pr_debug("no interface?\n"); pr_debug("no interface?\n");
...@@ -307,7 +307,6 @@ static int chnl_net_open(struct net_device *dev) ...@@ -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, dev->mtu, lldev->mtu - (headroom + tailroom));
mtu = min_t(int, GPRS_PDP_MTU, mtu); mtu = min_t(int, GPRS_PDP_MTU, mtu);
dev_set_mtu(dev, mtu); dev_set_mtu(dev, mtu);
dev_put(lldev);
if (mtu < 100) { if (mtu < 100) {
pr_warn("CAIF Interface MTU too small (%d)\n", mtu); pr_warn("CAIF Interface MTU too small (%d)\n", mtu);
......
...@@ -839,21 +839,21 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -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) if (!gwj->ccgw.src_idx || !gwj->ccgw.dst_idx)
goto out; 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) if (!gwj->src.dev)
goto out; goto out;
if (gwj->src.dev->type != ARPHRD_CAN) 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) if (!gwj->dst.dev)
goto put_src_out; goto out;
if (gwj->dst.dev->type != ARPHRD_CAN) if (gwj->dst.dev->type != ARPHRD_CAN)
goto put_src_dst_out; goto out;
gwj->limit_hops = limhops; gwj->limit_hops = limhops;
...@@ -862,11 +862,6 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -862,11 +862,6 @@ static int cgw_create_job(struct sk_buff *skb, struct nlmsghdr *nlh)
err = cgw_register_filter(gwj); err = cgw_register_filter(gwj);
if (!err) if (!err)
hlist_add_head_rcu(&gwj->list, &cgw_list); 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: out:
if (err) if (err)
kmem_cache_free(cgw_cache, gwj); kmem_cache_free(cgw_cache, gwj);
......
...@@ -1688,21 +1688,17 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1688,21 +1688,17 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh)
if (!tb[DCB_ATTR_IFNAME]) if (!tb[DCB_ATTR_IFNAME])
return -EINVAL; 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) if (!netdev)
return -ENODEV; return -ENODEV;
if (!netdev->dcbnl_ops) { if (!netdev->dcbnl_ops)
ret = -EOPNOTSUPP; return -EOPNOTSUPP;
goto out;
}
reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq, reply_skb = dcbnl_newmsg(fn->type, dcb->cmd, portid, nlh->nlmsg_seq,
nlh->nlmsg_flags, &reply_nlh); nlh->nlmsg_flags, &reply_nlh);
if (!reply_skb) { if (!reply_skb)
ret = -ENOBUFS; return -ENOBUFS;
goto out;
}
ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb); ret = fn->cb(netdev, nlh, nlh->nlmsg_seq, tb, reply_skb);
if (ret < 0) { if (ret < 0) {
...@@ -1714,7 +1710,6 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1714,7 +1710,6 @@ static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh)
ret = rtnl_unicast(reply_skb, net, portid); ret = rtnl_unicast(reply_skb, net, portid);
out: out:
dev_put(netdev);
return ret; return ret;
} }
......
...@@ -1666,12 +1666,8 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh) ...@@ -1666,12 +1666,8 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh)
if (fld.flowidn_iif) { if (fld.flowidn_iif) {
struct net_device *dev; struct net_device *dev;
if ((dev = dev_get_by_index(&init_net, fld.flowidn_iif)) == NULL) { dev = __dev_get_by_index(&init_net, fld.flowidn_iif);
kfree_skb(skb); if (!dev || !dev->dn_ptr) {
return -ENODEV;
}
if (!dev->dn_ptr) {
dev_put(dev);
kfree_skb(skb); kfree_skb(skb);
return -ENODEV; return -ENODEV;
} }
...@@ -1693,8 +1689,6 @@ static int dn_cache_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh) ...@@ -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); err = dn_route_output_key((struct dst_entry **)&rt, &fld, 0);
} }
if (skb->dev)
dev_put(skb->dev);
skb->dev = NULL; skb->dev = NULL;
if (err) if (err)
goto out_free; goto out_free;
......
...@@ -165,7 +165,7 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) ...@@ -165,7 +165,7 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
if (attrs[NL80211_ATTR_IFINDEX]) { if (attrs[NL80211_ATTR_IFINDEX]) {
int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
netdev = dev_get_by_index(netns, ifindex); netdev = __dev_get_by_index(netns, ifindex);
if (netdev) { if (netdev) {
if (netdev->ieee80211_ptr) if (netdev->ieee80211_ptr)
tmp = wiphy_to_dev( tmp = wiphy_to_dev(
...@@ -173,8 +173,6 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) ...@@ -173,8 +173,6 @@ __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
else else
tmp = NULL; tmp = NULL;
dev_put(netdev);
/* not wireless device -- return error */ /* not wireless device -- return error */
if (!tmp) if (!tmp)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -1656,7 +1654,7 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb, ...@@ -1656,7 +1654,7 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
struct cfg80211_registered_device *rdev; struct cfg80211_registered_device *rdev;
int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
netdev = dev_get_by_index(sock_net(skb->sk), ifidx); netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
if (!netdev) if (!netdev)
return -ENODEV; return -ENODEV;
if (netdev->ieee80211_ptr) { if (netdev->ieee80211_ptr) {
...@@ -1664,7 +1662,6 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb, ...@@ -1664,7 +1662,6 @@ static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
netdev->ieee80211_ptr->wiphy); netdev->ieee80211_ptr->wiphy);
state->filter_wiphy = rdev->wiphy_idx; state->filter_wiphy = rdev->wiphy_idx;
} }
dev_put(netdev);
} }
return 0; return 0;
...@@ -1987,7 +1984,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -1987,7 +1984,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
if (info->attrs[NL80211_ATTR_IFINDEX]) { if (info->attrs[NL80211_ATTR_IFINDEX]) {
int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
netdev = dev_get_by_index(genl_info_net(info), ifindex); netdev = __dev_get_by_index(genl_info_net(info), ifindex);
if (netdev && netdev->ieee80211_ptr) if (netdev && netdev->ieee80211_ptr)
rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy);
else else
...@@ -2015,32 +2012,24 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2015,32 +2012,24 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
if (result) if (result)
goto bad_res; return result;
if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
struct ieee80211_txq_params txq_params; struct ieee80211_txq_params txq_params;
struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
if (!rdev->ops->set_txq_params) { if (!rdev->ops->set_txq_params)
result = -EOPNOTSUPP; return -EOPNOTSUPP;
goto bad_res;
}
if (!netdev) { if (!netdev)
result = -EINVAL; return -EINVAL;
goto bad_res;
}
if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
result = -EINVAL; return -EINVAL;
goto bad_res;
}
if (!netif_running(netdev)) { if (!netif_running(netdev))
result = -ENETDOWN; return -ENETDOWN;
goto bad_res;
}
nla_for_each_nested(nl_txq_params, nla_for_each_nested(nl_txq_params,
info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
...@@ -2051,12 +2040,12 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2051,12 +2040,12 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
txq_params_policy); txq_params_policy);
result = parse_txq_params(tb, &txq_params); result = parse_txq_params(tb, &txq_params);
if (result) if (result)
goto bad_res; return result;
result = rdev_set_txq_params(rdev, netdev, result = rdev_set_txq_params(rdev, netdev,
&txq_params); &txq_params);
if (result) if (result)
goto bad_res; return result;
} }
} }
...@@ -2065,7 +2054,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2065,7 +2054,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
nl80211_can_set_dev_channel(wdev) ? wdev : NULL, nl80211_can_set_dev_channel(wdev) ? wdev : NULL,
info); info);
if (result) if (result)
goto bad_res; return result;
} }
if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
...@@ -2076,19 +2065,15 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2076,19 +2065,15 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
txp_wdev = NULL; txp_wdev = NULL;
if (!rdev->ops->set_tx_power) { if (!rdev->ops->set_tx_power)
result = -EOPNOTSUPP; return -EOPNOTSUPP;
goto bad_res;
}
idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
type = nla_get_u32(info->attrs[idx]); type = nla_get_u32(info->attrs[idx]);
if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
(type != NL80211_TX_POWER_AUTOMATIC)) { (type != NL80211_TX_POWER_AUTOMATIC))
result = -EINVAL; return -EINVAL;
goto bad_res;
}
if (type != NL80211_TX_POWER_AUTOMATIC) { if (type != NL80211_TX_POWER_AUTOMATIC) {
idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
...@@ -2097,7 +2082,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2097,7 +2082,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
if (result) if (result)
goto bad_res; return result;
} }
if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
...@@ -2105,10 +2090,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2105,10 +2090,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
u32 tx_ant, rx_ant; u32 tx_ant, rx_ant;
if ((!rdev->wiphy.available_antennas_tx && if ((!rdev->wiphy.available_antennas_tx &&
!rdev->wiphy.available_antennas_rx) || !rdev->wiphy.available_antennas_rx) ||
!rdev->ops->set_antenna) { !rdev->ops->set_antenna)
result = -EOPNOTSUPP; return -EOPNOTSUPP;
goto bad_res;
}
tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
...@@ -2116,17 +2099,15 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2116,17 +2099,15 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
/* reject antenna configurations which don't match the /* reject antenna configurations which don't match the
* available antenna masks, except for the "all" mask */ * available antenna masks, except for the "all" mask */
if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
(~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
result = -EINVAL; return -EINVAL;
goto bad_res;
}
tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
result = rdev_set_antenna(rdev, tx_ant, rx_ant); result = rdev_set_antenna(rdev, tx_ant, rx_ant);
if (result) if (result)
goto bad_res; return result;
} }
changed = 0; changed = 0;
...@@ -2134,30 +2115,27 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2134,30 +2115,27 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
retry_short = nla_get_u8( retry_short = nla_get_u8(
info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
if (retry_short == 0) { if (retry_short == 0)
result = -EINVAL; return -EINVAL;
goto bad_res;
}
changed |= WIPHY_PARAM_RETRY_SHORT; changed |= WIPHY_PARAM_RETRY_SHORT;
} }
if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
retry_long = nla_get_u8( retry_long = nla_get_u8(
info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
if (retry_long == 0) { if (retry_long == 0)
result = -EINVAL; return -EINVAL;
goto bad_res;
}
changed |= WIPHY_PARAM_RETRY_LONG; changed |= WIPHY_PARAM_RETRY_LONG;
} }
if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
frag_threshold = nla_get_u32( frag_threshold = nla_get_u32(
info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
if (frag_threshold < 256) { if (frag_threshold < 256)
result = -EINVAL; return -EINVAL;
goto bad_res;
}
if (frag_threshold != (u32) -1) { if (frag_threshold != (u32) -1) {
/* /*
* Fragments (apart from the last one) are required to * Fragments (apart from the last one) are required to
...@@ -2187,10 +2165,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2187,10 +2165,8 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
u32 old_frag_threshold, old_rts_threshold; u32 old_frag_threshold, old_rts_threshold;
u8 old_coverage_class; u8 old_coverage_class;
if (!rdev->ops->set_wiphy_params) { if (!rdev->ops->set_wiphy_params)
result = -EOPNOTSUPP; return -EOPNOTSUPP;
goto bad_res;
}
old_retry_short = rdev->wiphy.retry_short; old_retry_short = rdev->wiphy.retry_short;
old_retry_long = rdev->wiphy.retry_long; old_retry_long = rdev->wiphy.retry_long;
...@@ -2218,11 +2194,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) ...@@ -2218,11 +2194,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
rdev->wiphy.coverage_class = old_coverage_class; rdev->wiphy.coverage_class = old_coverage_class;
} }
} }
return 0;
bad_res:
if (netdev)
dev_put(netdev);
return result;
} }
static inline u64 wdev_id(struct wireless_dev *wdev) static inline u64 wdev_id(struct wireless_dev *wdev)
......
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