hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/mac80211/mesh_pathtbl.c
....@@ -47,32 +47,24 @@
4747 mesh_path_free_rcu(tbl, mpath);
4848 }
4949
50
-static struct mesh_table *mesh_table_alloc(void)
50
+static void mesh_table_init(struct mesh_table *tbl)
5151 {
52
- struct mesh_table *newtbl;
52
+ INIT_HLIST_HEAD(&tbl->known_gates);
53
+ INIT_HLIST_HEAD(&tbl->walk_head);
54
+ atomic_set(&tbl->entries, 0);
55
+ spin_lock_init(&tbl->gates_lock);
56
+ spin_lock_init(&tbl->walk_lock);
5357
54
- newtbl = kmalloc(sizeof(struct mesh_table), GFP_ATOMIC);
55
- if (!newtbl)
56
- return NULL;
57
-
58
- INIT_HLIST_HEAD(&newtbl->known_gates);
59
- INIT_HLIST_HEAD(&newtbl->walk_head);
60
- atomic_set(&newtbl->entries, 0);
61
- spin_lock_init(&newtbl->gates_lock);
62
- spin_lock_init(&newtbl->walk_lock);
63
- if (rhashtable_init(&newtbl->rhead, &mesh_rht_params)) {
64
- kfree(newtbl);
65
- return NULL;
66
- }
67
-
68
- return newtbl;
58
+ /* rhashtable_init() may fail only in case of wrong
59
+ * mesh_rht_params
60
+ */
61
+ WARN_ON(rhashtable_init(&tbl->rhead, &mesh_rht_params));
6962 }
7063
7164 static void mesh_table_free(struct mesh_table *tbl)
7265 {
7366 rhashtable_free_and_destroy(&tbl->rhead,
7467 mesh_path_rht_free, tbl);
75
- kfree(tbl);
7668 }
7769
7870 /**
....@@ -238,13 +230,13 @@
238230 struct mesh_path *
239231 mesh_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst)
240232 {
241
- return mpath_lookup(sdata->u.mesh.mesh_paths, dst, sdata);
233
+ return mpath_lookup(&sdata->u.mesh.mesh_paths, dst, sdata);
242234 }
243235
244236 struct mesh_path *
245237 mpp_path_lookup(struct ieee80211_sub_if_data *sdata, const u8 *dst)
246238 {
247
- return mpath_lookup(sdata->u.mesh.mpp_paths, dst, sdata);
239
+ return mpath_lookup(&sdata->u.mesh.mpp_paths, dst, sdata);
248240 }
249241
250242 static struct mesh_path *
....@@ -281,7 +273,7 @@
281273 struct mesh_path *
282274 mesh_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
283275 {
284
- return __mesh_path_lookup_by_idx(sdata->u.mesh.mesh_paths, idx);
276
+ return __mesh_path_lookup_by_idx(&sdata->u.mesh.mesh_paths, idx);
285277 }
286278
287279 /**
....@@ -296,7 +288,7 @@
296288 struct mesh_path *
297289 mpp_path_lookup_by_idx(struct ieee80211_sub_if_data *sdata, int idx)
298290 {
299
- return __mesh_path_lookup_by_idx(sdata->u.mesh.mpp_paths, idx);
291
+ return __mesh_path_lookup_by_idx(&sdata->u.mesh.mpp_paths, idx);
300292 }
301293
302294 /**
....@@ -309,7 +301,7 @@
309301 int err;
310302
311303 rcu_read_lock();
312
- tbl = mpath->sdata->u.mesh.mesh_paths;
304
+ tbl = &mpath->sdata->u.mesh.mesh_paths;
313305
314306 spin_lock_bh(&mpath->state_lock);
315307 if (mpath->is_gate) {
....@@ -418,7 +410,7 @@
418410 if (!new_mpath)
419411 return ERR_PTR(-ENOMEM);
420412
421
- tbl = sdata->u.mesh.mesh_paths;
413
+ tbl = &sdata->u.mesh.mesh_paths;
422414 spin_lock_bh(&tbl->walk_lock);
423415 mpath = rhashtable_lookup_get_insert_fast(&tbl->rhead,
424416 &new_mpath->rhash,
....@@ -460,7 +452,7 @@
460452 return -ENOMEM;
461453
462454 memcpy(new_mpath->mpp, mpp, ETH_ALEN);
463
- tbl = sdata->u.mesh.mpp_paths;
455
+ tbl = &sdata->u.mesh.mpp_paths;
464456
465457 spin_lock_bh(&tbl->walk_lock);
466458 ret = rhashtable_lookup_insert_fast(&tbl->rhead,
....@@ -489,7 +481,7 @@
489481 void mesh_plink_broken(struct sta_info *sta)
490482 {
491483 struct ieee80211_sub_if_data *sdata = sta->sdata;
492
- struct mesh_table *tbl = sdata->u.mesh.mesh_paths;
484
+ struct mesh_table *tbl = &sdata->u.mesh.mesh_paths;
493485 static const u8 bcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
494486 struct mesh_path *mpath;
495487
....@@ -548,7 +540,7 @@
548540 void mesh_path_flush_by_nexthop(struct sta_info *sta)
549541 {
550542 struct ieee80211_sub_if_data *sdata = sta->sdata;
551
- struct mesh_table *tbl = sdata->u.mesh.mesh_paths;
543
+ struct mesh_table *tbl = &sdata->u.mesh.mesh_paths;
552544 struct mesh_path *mpath;
553545 struct hlist_node *n;
554546
....@@ -563,7 +555,7 @@
563555 static void mpp_flush_by_proxy(struct ieee80211_sub_if_data *sdata,
564556 const u8 *proxy)
565557 {
566
- struct mesh_table *tbl = sdata->u.mesh.mpp_paths;
558
+ struct mesh_table *tbl = &sdata->u.mesh.mpp_paths;
567559 struct mesh_path *mpath;
568560 struct hlist_node *n;
569561
....@@ -597,8 +589,8 @@
597589 */
598590 void mesh_path_flush_by_iface(struct ieee80211_sub_if_data *sdata)
599591 {
600
- table_flush_by_iface(sdata->u.mesh.mesh_paths);
601
- table_flush_by_iface(sdata->u.mesh.mpp_paths);
592
+ table_flush_by_iface(&sdata->u.mesh.mesh_paths);
593
+ table_flush_by_iface(&sdata->u.mesh.mpp_paths);
602594 }
603595
604596 /**
....@@ -644,7 +636,7 @@
644636 /* flush relevant mpp entries first */
645637 mpp_flush_by_proxy(sdata, addr);
646638
647
- err = table_path_del(sdata->u.mesh.mesh_paths, sdata, addr);
639
+ err = table_path_del(&sdata->u.mesh.mesh_paths, sdata, addr);
648640 sdata->u.mesh.mesh_paths_generation++;
649641 return err;
650642 }
....@@ -682,7 +674,7 @@
682674 struct mesh_path *gate;
683675 bool copy = false;
684676
685
- tbl = sdata->u.mesh.mesh_paths;
677
+ tbl = &sdata->u.mesh.mesh_paths;
686678
687679 rcu_read_lock();
688680 hlist_for_each_entry_rcu(gate, &tbl->known_gates, gate_list) {
....@@ -762,29 +754,10 @@
762754 mesh_path_tx_pending(mpath);
763755 }
764756
765
-int mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata)
757
+void mesh_pathtbl_init(struct ieee80211_sub_if_data *sdata)
766758 {
767
- struct mesh_table *tbl_path, *tbl_mpp;
768
- int ret;
769
-
770
- tbl_path = mesh_table_alloc();
771
- if (!tbl_path)
772
- return -ENOMEM;
773
-
774
- tbl_mpp = mesh_table_alloc();
775
- if (!tbl_mpp) {
776
- ret = -ENOMEM;
777
- goto free_path;
778
- }
779
-
780
- sdata->u.mesh.mesh_paths = tbl_path;
781
- sdata->u.mesh.mpp_paths = tbl_mpp;
782
-
783
- return 0;
784
-
785
-free_path:
786
- mesh_table_free(tbl_path);
787
- return ret;
759
+ mesh_table_init(&sdata->u.mesh.mesh_paths);
760
+ mesh_table_init(&sdata->u.mesh.mpp_paths);
788761 }
789762
790763 static
....@@ -806,12 +779,12 @@
806779
807780 void mesh_path_expire(struct ieee80211_sub_if_data *sdata)
808781 {
809
- mesh_path_tbl_expire(sdata, sdata->u.mesh.mesh_paths);
810
- mesh_path_tbl_expire(sdata, sdata->u.mesh.mpp_paths);
782
+ mesh_path_tbl_expire(sdata, &sdata->u.mesh.mesh_paths);
783
+ mesh_path_tbl_expire(sdata, &sdata->u.mesh.mpp_paths);
811784 }
812785
813786 void mesh_pathtbl_unregister(struct ieee80211_sub_if_data *sdata)
814787 {
815
- mesh_table_free(sdata->u.mesh.mesh_paths);
816
- mesh_table_free(sdata->u.mesh.mpp_paths);
788
+ mesh_table_free(&sdata->u.mesh.mesh_paths);
789
+ mesh_table_free(&sdata->u.mesh.mpp_paths);
817790 }