aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2012-06-15 07:32:49 -0400
committerJohannes Berg <johannes.berg@intel.com>2012-06-20 04:56:59 -0400
commita9455408b09395ecf4008bd998516ce2e9551bbc (patch)
treeee8323f0e78f583e9ff34c1cc9cd578674a6a132 /net
parent6df653c71e8168e1df01118cc85cd84d0deeb583 (diff)
cfg80211: make some functions static
Some of the functions to retrieve a device can be static as they're used only in nl80211. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net')
-rw-r--r--net/wireless/core.c63
-rw-r--r--net/wireless/core.h26
-rw-r--r--net/wireless/nl80211.c82
3 files changed, 82 insertions, 89 deletions
diff --git a/net/wireless/core.c b/net/wireless/core.c
index a87d43552974..907f62c80e28 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -96,69 +96,6 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
96 return &rdev->wiphy; 96 return &rdev->wiphy;
97} 97}
98 98
99/* requires cfg80211_mutex to be held! */
100struct cfg80211_registered_device *
101__cfg80211_rdev_from_info(struct genl_info *info)
102{
103 int ifindex;
104 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL;
105 struct net_device *dev;
106 int err = -EINVAL;
107
108 assert_cfg80211_lock();
109
110 if (info->attrs[NL80211_ATTR_WIPHY]) {
111 bywiphyidx = cfg80211_rdev_by_wiphy_idx(
112 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
113 err = -ENODEV;
114 }
115
116 if (info->attrs[NL80211_ATTR_IFINDEX]) {
117 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
118 dev = dev_get_by_index(genl_info_net(info), ifindex);
119 if (dev) {
120 if (dev->ieee80211_ptr)
121 byifidx =
122 wiphy_to_dev(dev->ieee80211_ptr->wiphy);
123 dev_put(dev);
124 }
125 err = -ENODEV;
126 }
127
128 if (bywiphyidx && byifidx) {
129 if (bywiphyidx != byifidx)
130 return ERR_PTR(-EINVAL);
131 else
132 return bywiphyidx; /* == byifidx */
133 }
134 if (bywiphyidx)
135 return bywiphyidx;
136
137 if (byifidx)
138 return byifidx;
139
140 return ERR_PTR(err);
141}
142
143struct cfg80211_registered_device *
144cfg80211_get_dev_from_info(struct genl_info *info)
145{
146 struct cfg80211_registered_device *rdev;
147
148 mutex_lock(&cfg80211_mutex);
149 rdev = __cfg80211_rdev_from_info(info);
150
151 /* if it is not an error we grab the lock on
152 * it to assure it won't be going away while
153 * we operate on it */
154 if (!IS_ERR(rdev))
155 mutex_lock(&rdev->mtx);
156
157 mutex_unlock(&cfg80211_mutex);
158
159 return rdev;
160}
161
162struct cfg80211_registered_device * 99struct cfg80211_registered_device *
163cfg80211_get_dev_from_ifindex(struct net *net, int ifindex) 100cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)
164{ 101{
diff --git a/net/wireless/core.h b/net/wireless/core.h
index 9348a47562a4..609a579255ac 100644
--- a/net/wireless/core.h
+++ b/net/wireless/core.h
@@ -159,32 +159,6 @@ static inline void cfg80211_unhold_bss(struct cfg80211_internal_bss *bss)
159struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx); 159struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx);
160int get_wiphy_idx(struct wiphy *wiphy); 160int get_wiphy_idx(struct wiphy *wiphy);
161 161
162struct cfg80211_registered_device *
163__cfg80211_rdev_from_info(struct genl_info *info);
164
165/*
166 * This function returns a pointer to the driver
167 * that the genl_info item that is passed refers to.
168 * If successful, it returns non-NULL and also locks
169 * the driver's mutex!
170 *
171 * This means that you need to call cfg80211_unlock_rdev()
172 * before being allowed to acquire &cfg80211_mutex!
173 *
174 * This is necessary because we need to lock the global
175 * mutex to get an item off the list safely, and then
176 * we lock the rdev mutex so it doesn't go away under us.
177 *
178 * We don't want to keep cfg80211_mutex locked
179 * for all the time in order to allow requests on
180 * other interfaces to go through at the same time.
181 *
182 * The result of this can be a PTR_ERR and hence must
183 * be checked with IS_ERR() for errors.
184 */
185extern struct cfg80211_registered_device *
186cfg80211_get_dev_from_info(struct genl_info *info);
187
188/* requires cfg80211_rdev_mutex to be held! */ 162/* requires cfg80211_rdev_mutex to be held! */
189struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx); 163struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx);
190 164
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index a363ca17bfc5..2d3541c5e058 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -70,6 +70,88 @@ static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs,
70 return 0; 70 return 0;
71} 71}
72 72
73static struct cfg80211_registered_device *
74__cfg80211_rdev_from_info(struct genl_info *info)
75{
76 int ifindex;
77 struct cfg80211_registered_device *bywiphyidx = NULL, *byifidx = NULL;
78 struct net_device *dev;
79 int err = -EINVAL;
80
81 assert_cfg80211_lock();
82
83 if (info->attrs[NL80211_ATTR_WIPHY]) {
84 bywiphyidx = cfg80211_rdev_by_wiphy_idx(
85 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
86 err = -ENODEV;
87 }
88
89 if (info->attrs[NL80211_ATTR_IFINDEX]) {
90 ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
91 dev = dev_get_by_index(genl_info_net(info), ifindex);
92 if (dev) {
93 if (dev->ieee80211_ptr)
94 byifidx =
95 wiphy_to_dev(dev->ieee80211_ptr->wiphy);
96 dev_put(dev);
97 }
98 err = -ENODEV;
99 }
100
101 if (bywiphyidx && byifidx) {
102 if (bywiphyidx != byifidx)
103 return ERR_PTR(-EINVAL);
104 else
105 return bywiphyidx; /* == byifidx */
106 }
107 if (bywiphyidx)
108 return bywiphyidx;
109
110 if (byifidx)
111 return byifidx;
112
113 return ERR_PTR(err);
114}
115
116/*
117 * This function returns a pointer to the driver
118 * that the genl_info item that is passed refers to.
119 * If successful, it returns non-NULL and also locks
120 * the driver's mutex!
121 *
122 * This means that you need to call cfg80211_unlock_rdev()
123 * before being allowed to acquire &cfg80211_mutex!
124 *
125 * This is necessary because we need to lock the global
126 * mutex to get an item off the list safely, and then
127 * we lock the rdev mutex so it doesn't go away under us.
128 *
129 * We don't want to keep cfg80211_mutex locked
130 * for all the time in order to allow requests on
131 * other interfaces to go through at the same time.
132 *
133 * The result of this can be a PTR_ERR and hence must
134 * be checked with IS_ERR() for errors.
135 */
136static struct cfg80211_registered_device *
137cfg80211_get_dev_from_info(struct genl_info *info)
138{
139 struct cfg80211_registered_device *rdev;
140
141 mutex_lock(&cfg80211_mutex);
142 rdev = __cfg80211_rdev_from_info(info);
143
144 /* if it is not an error we grab the lock on
145 * it to assure it won't be going away while
146 * we operate on it */
147 if (!IS_ERR(rdev))
148 mutex_lock(&rdev->mtx);
149
150 mutex_unlock(&cfg80211_mutex);
151
152 return rdev;
153}
154
73/* policy for the attributes */ 155/* policy for the attributes */
74static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { 156static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = {
75 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, 157 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },