1 From: Henning Rogge <hrogge@gmail.com>
2 Date: Wed, 3 Feb 2016 13:58:38 +0100
3 Subject: [PATCH] mac80211: Unify mesh and mpp path removal function
5 mpp_path_del() and mesh_path_del() are mostly the same function.
6 Move common code into a new static function.
8 Acked-by: Bob Copeland <me@bobcopeland.com>
9 Signed-off-by: Henning Rogge <henning.rogge@fkie.fraunhofer.de>
10 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
13 --- a/net/mac80211/mesh_pathtbl.c
14 +++ b/net/mac80211/mesh_pathtbl.c
15 @@ -55,16 +55,21 @@ int mpp_paths_generation;
16 static DEFINE_RWLOCK(pathtbl_resize_lock);
19 +static inline struct mesh_table *resize_dereference_paths(
20 + struct mesh_table __rcu *table)
22 + return rcu_dereference_protected(table,
23 + lockdep_is_held(&pathtbl_resize_lock));
26 static inline struct mesh_table *resize_dereference_mesh_paths(void)
28 - return rcu_dereference_protected(mesh_paths,
29 - lockdep_is_held(&pathtbl_resize_lock));
30 + return resize_dereference_paths(mesh_paths);
33 static inline struct mesh_table *resize_dereference_mpp_paths(void)
35 - return rcu_dereference_protected(mpp_paths,
36 - lockdep_is_held(&pathtbl_resize_lock));
37 + return resize_dereference_paths(mpp_paths);
41 @@ -899,14 +904,17 @@ void mesh_path_flush_by_iface(struct iee
45 - * mesh_path_del - delete a mesh path from the table
46 + * table_path_del - delete a path from the mesh or mpp table
48 - * @addr: dst address (ETH_ALEN length)
49 + * @tbl: mesh or mpp path table
51 + * @addr: dst address (ETH_ALEN length)
53 * Returns: 0 if successful
55 -int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
56 +static int table_path_del(struct mesh_table __rcu *rcu_tbl,
57 + struct ieee80211_sub_if_data *sdata,
60 struct mesh_table *tbl;
61 struct mesh_path *mpath;
62 @@ -915,11 +923,7 @@ int mesh_path_del(struct ieee80211_sub_i
66 - /* flush relevant mpp entries first */
67 - mpp_flush_by_proxy(sdata, addr);
69 - read_lock_bh(&pathtbl_resize_lock);
70 - tbl = resize_dereference_mesh_paths();
71 + tbl = resize_dereference_paths(rcu_tbl);
72 hash_idx = mesh_table_hash(addr, sdata, tbl);
73 bucket = &tbl->hash_buckets[hash_idx];
75 @@ -935,9 +939,30 @@ int mesh_path_del(struct ieee80211_sub_i
79 - mesh_paths_generation++;
80 spin_unlock(&tbl->hashwlock[hash_idx]);
85 + * mesh_path_del - delete a mesh path from the table
87 + * @addr: dst address (ETH_ALEN length)
88 + * @sdata: local subif
90 + * Returns: 0 if successful
92 +int mesh_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
96 + /* flush relevant mpp entries first */
97 + mpp_flush_by_proxy(sdata, addr);
99 + read_lock_bh(&pathtbl_resize_lock);
100 + err = table_path_del(mesh_paths, sdata, addr);
101 + mesh_paths_generation++;
102 read_unlock_bh(&pathtbl_resize_lock);
107 @@ -951,33 +976,13 @@ enddel:
109 static int mpp_path_del(struct ieee80211_sub_if_data *sdata, const u8 *addr)
111 - struct mesh_table *tbl;
112 - struct mesh_path *mpath;
113 - struct mpath_node *node;
114 - struct hlist_head *bucket;
118 read_lock_bh(&pathtbl_resize_lock);
119 - tbl = resize_dereference_mpp_paths();
120 - hash_idx = mesh_table_hash(addr, sdata, tbl);
121 - bucket = &tbl->hash_buckets[hash_idx];
123 - spin_lock(&tbl->hashwlock[hash_idx]);
124 - hlist_for_each_entry(node, bucket, list) {
125 - mpath = node->mpath;
126 - if (mpath->sdata == sdata &&
127 - ether_addr_equal(addr, mpath->dst)) {
128 - __mesh_path_del(tbl, node);
135 - mesh_paths_generation++;
136 - spin_unlock(&tbl->hashwlock[hash_idx]);
137 + err = table_path_del(mpp_paths, sdata, addr);
138 + mpp_paths_generation++;
139 read_unlock_bh(&pathtbl_resize_lock);