Commit 7fee4778 authored by Johannes Berg's avatar Johannes Berg

nl80211: refactor __cfg80211_rdev_from_info

Refactor the function to make it easier to
extend.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent a9455408
...@@ -73,44 +73,47 @@ static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, ...@@ -73,44 +73,47 @@ static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
static struct cfg80211_registered_device * static struct cfg80211_registered_device *
__cfg80211_rdev_from_info(struct genl_info *info) __cfg80211_rdev_from_info(struct genl_info *info)
{ {
int ifindex; struct cfg80211_registered_device *rdev = NULL, *tmp;
struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL; struct net_device *netdev;
struct net_device *dev;
int err = -EINVAL;
assert_cfg80211_lock(); assert_cfg80211_lock();
if (info->attrs[NL80211_ATTR_WIPHY]) { if (!info->attrs[NL80211_ATTR_WIPHY] &&
bywiphyidx = cfg80211_rdev_by_wiphy_idx( !info->attrs[NL80211_ATTR_IFINDEX])
return ERR_PTR(-EINVAL);
if (info->attrs[NL80211_ATTR_WIPHY])
rdev = cfg80211_rdev_by_wiphy_idx(
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY])); nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
err = -ENODEV;
}
if (info->attrs[NL80211_ATTR_IFINDEX]) { if (info->attrs[NL80211_ATTR_IFINDEX]) {
ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
dev = dev_get_by_index(genl_info_net(info), ifindex); netdev = dev_get_by_index(genl_info_net(info), ifindex);
if (dev) { if (netdev) {
if (dev->ieee80211_ptr) if (netdev->ieee80211_ptr)
byifidx = tmp = wiphy_to_dev(
wiphy_to_dev(dev->ieee80211_ptr->wiphy); netdev->ieee80211_ptr->wiphy);
dev_put(dev); else
} tmp = NULL;
err = -ENODEV;
} dev_put(netdev);
if (bywiphyidx && byifidx) { /* not wireless device -- return error */
if (bywiphyidx != byifidx) if (!tmp)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
else
return bywiphyidx; /* == byifidx */ /* mismatch -- return error */
if (rdev && tmp != rdev)
return ERR_PTR(-EINVAL);
rdev = tmp;
}
} }
if (bywiphyidx)
return bywiphyidx;
if (byifidx) if (rdev)
return byifidx; return rdev;
return ERR_PTR(err); return ERR_PTR(-ENODEV);
} }
/* /*
......
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