aboutsummaryrefslogtreecommitdiffstats
path: root/net/wireless/core.c
diff options
context:
space:
mode:
authorBen Greear <greearb@candelatech.com>2014-10-22 15:23:00 -0400
committerJohannes Berg <johannes.berg@intel.com>2014-10-27 03:48:18 -0400
commit1998d90ad424c1ff12ea24816ce158d5262e06a5 (patch)
treead30c598208b3c85525810af268787cad5bb774d /net/wireless/core.c
parent8cdd9e1c37dd888894922b8209d5fc8055cfde52 (diff)
cfg80211: support creating wiphy with suggested name
Kernel will attempt to use the name if it is supplied, but if name cannot be used for some reason, the default phyX name will be used instead. Signed-off-by: Ben Greear <greearb@candelatech.com> [while at it, use wiphy_name() instead of dev_name(), fix format string issue reported by Kees Cook] Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/wireless/core.c')
-rw-r--r--net/wireless/core.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/net/wireless/core.c b/net/wireless/core.c
index f52a4cd7017c..87bb502bc8de 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -86,11 +86,11 @@ struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
86 return &rdev->wiphy; 86 return &rdev->wiphy;
87} 87}
88 88
89int cfg80211_dev_rename(struct cfg80211_registered_device *rdev, 89static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev,
90 char *newname) 90 const char *newname)
91{ 91{
92 struct cfg80211_registered_device *rdev2; 92 struct cfg80211_registered_device *rdev2;
93 int wiphy_idx, taken = -1, result, digits; 93 int wiphy_idx, taken = -1, digits;
94 94
95 ASSERT_RTNL(); 95 ASSERT_RTNL();
96 96
@@ -109,15 +109,28 @@ int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
109 return -EINVAL; 109 return -EINVAL;
110 } 110 }
111 111
112 /* Ensure another device does not already have this name. */
113 list_for_each_entry(rdev2, &cfg80211_rdev_list, list)
114 if (strcmp(newname, wiphy_name(&rdev2->wiphy)) == 0)
115 return -EINVAL;
116
117 return 0;
118}
119
120int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
121 char *newname)
122{
123 int result;
124
125 ASSERT_RTNL();
112 126
113 /* Ignore nop renames */ 127 /* Ignore nop renames */
114 if (strcmp(newname, dev_name(&rdev->wiphy.dev)) == 0) 128 if (strcmp(newname, wiphy_name(&rdev->wiphy)) == 0)
115 return 0; 129 return 0;
116 130
117 /* Ensure another device does not already have this name. */ 131 result = cfg80211_dev_check_name(rdev, newname);
118 list_for_each_entry(rdev2, &cfg80211_rdev_list, list) 132 if (result < 0)
119 if (strcmp(newname, dev_name(&rdev2->wiphy.dev)) == 0) 133 return result;
120 return -EINVAL;
121 134
122 result = device_rename(&rdev->wiphy.dev, newname); 135 result = device_rename(&rdev->wiphy.dev, newname);
123 if (result) 136 if (result)
@@ -309,7 +322,8 @@ static void cfg80211_destroy_iface_wk(struct work_struct *work)
309 322
310/* exported functions */ 323/* exported functions */
311 324
312struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv) 325struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv,
326 const char *requested_name)
313{ 327{
314 static atomic_t wiphy_counter = ATOMIC_INIT(0); 328 static atomic_t wiphy_counter = ATOMIC_INIT(0);
315 329
@@ -346,7 +360,31 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
346 rdev->wiphy_idx--; 360 rdev->wiphy_idx--;
347 361
348 /* give it a proper name */ 362 /* give it a proper name */
349 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx); 363 if (requested_name && requested_name[0]) {
364 int rv;
365
366 rtnl_lock();
367 rv = cfg80211_dev_check_name(rdev, requested_name);
368
369 if (rv < 0) {
370 rtnl_unlock();
371 goto use_default_name;
372 }
373
374 rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name);
375 rtnl_unlock();
376 if (rv)
377 goto use_default_name;
378 } else {
379use_default_name:
380 /* NOTE: This is *probably* safe w/out holding rtnl because of
381 * the restrictions on phy names. Probably this call could
382 * fail if some other part of the kernel (re)named a device
383 * phyX. But, might should add some locking and check return
384 * value, and use a different name if this one exists?
385 */
386 dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
387 }
350 388
351 INIT_LIST_HEAD(&rdev->wdev_list); 389 INIT_LIST_HEAD(&rdev->wdev_list);
352 INIT_LIST_HEAD(&rdev->beacon_registrations); 390 INIT_LIST_HEAD(&rdev->beacon_registrations);
@@ -406,7 +444,7 @@ struct wiphy *wiphy_new(const struct cfg80211_ops *ops, int sizeof_priv)
406 444
407 return &rdev->wiphy; 445 return &rdev->wiphy;
408} 446}
409EXPORT_SYMBOL(wiphy_new); 447EXPORT_SYMBOL(wiphy_new_nm);
410 448
411static int wiphy_verify_combinations(struct wiphy *wiphy) 449static int wiphy_verify_combinations(struct wiphy *wiphy)
412{ 450{