aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/nl80211.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2012-06-15 08:09:58 -0400
committerJohannes Berg <johannes.berg@intel.com>2012-06-20 04:57:00 -0400
commit7fee4778bf56b0c5c86010d5b6f654177cc5da96 (patch)
tree66a67e1ef07188fd9a875cf957075861e40fca7d /net/wireless/nl80211.c
parenta9455408b09395ecf4008bd998516ce2e9551bbc (diff)
nl80211: refactor __cfg80211_rdev_from_info
Refactor the function to make it easier to extend. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/wireless/nl80211.c')
-rw-r--r--net/wireless/nl80211.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 2d3541c5e058..0ec9779c2b56 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -73,44 +73,47 @@ static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
73static struct cfg80211_registered_device * 73static struct cfg80211_registered_device *
74__cfg80211_rdev_from_info(struct genl_info *info) 74__cfg80211_rdev_from_info(struct genl_info *info)
75{ 75{
76 int ifindex; 76 struct cfg80211_registered_device *rdev = NULL, *tmp;
77 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL; 77 struct net_device *netdev;
78 struct net_device *dev;
79 int err = -EINVAL;
80 78
81 assert_cfg80211_lock(); 79 assert_cfg80211_lock();
82 80
83 if (info->attrs[NL80211_ATTR_WIPHY]) { 81 if (!info->attrs[NL80211_ATTR_WIPHY] &&
84 bywiphyidx = cfg80211_rdev_by_wiphy_idx( 82 !info->attrs[NL80211_ATTR_IFINDEX])
83 return ERR_PTR(-EINVAL);
84
85 if (info->attrs[NL80211_ATTR_WIPHY])
86 rdev = cfg80211_rdev_by_wiphy_idx(
85 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY])); 87 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
86 err = -ENODEV;
87 }
88 88
89 if (info->attrs[NL80211_ATTR_IFINDEX]) { 89 if (info->attrs[NL80211_ATTR_IFINDEX]) {
90 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); 90 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
91 dev = dev_get_by_index(genl_info_net(info), ifindex); 91 netdev = dev_get_by_index(genl_info_net(info), ifindex);
92 if (dev) { 92 if (netdev) {
93 if (dev->ieee80211_ptr) 93 if (netdev->ieee80211_ptr)
94 byifidx = 94 tmp = wiphy_to_dev(
95 wiphy_to_dev(dev->ieee80211_ptr->wiphy); 95 netdev->ieee80211_ptr->wiphy);
96 dev_put(dev); 96 else
97 } 97 tmp = NULL;
98 err = -ENODEV;
99 }
100 98
101 if (bywiphyidx && byifidx) { 99 dev_put(netdev);
102 if (bywiphyidx != byifidx) 100
103 return ERR_PTR(-EINVAL); 101 /* not wireless device -- return error */
104 else 102 if (!tmp)
105 return bywiphyidx; /* == byifidx */ 103 return ERR_PTR(-EINVAL);
104
105 /* mismatch -- return error */
106 if (rdev && tmp != rdev)
107 return ERR_PTR(-EINVAL);
108
109 rdev = tmp;
110 }
106 } 111 }
107 if (bywiphyidx)
108 return bywiphyidx;
109 112
110 if (byifidx) 113 if (rdev)
111 return byifidx; 114 return rdev;
112 115
113 return ERR_PTR(err); 116 return ERR_PTR(-ENODEV);
114} 117}
115 118
116/* 119/*