summaryrefslogtreecommitdiffstats
path: root/net/mac80211
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2019-02-14 09:03:26 -0500
committerJohannes Berg <johannes.berg@intel.com>2019-02-22 07:48:48 -0500
commit3692293163b8ba1f28bad0e4a7ddf4fa0a7fd34d (patch)
tree24576379a6d0cb8f6c63d7e58f186587569bec37 /net/mac80211
parentb7b14ec1ebef35d22f3f4087816468f22c987f75 (diff)
mac80211: Use rhashtable_lookup_get_insert_fast instead of racy code
The code in mesh_path_add tries to handle the case where a duplicate entry is added to the rhashtable by doing a lookup after a failed insertion. It also tries to handle races by repeating the insertion should the lookup fail. This is now unnecessary as we have rhashtable API functions that can directly return the mathcing object. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'net/mac80211')
-rw-r--r--net/mac80211/mesh_pathtbl.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index 88a6d5e18ccc..95eb5064fa91 100644
--- a/net/mac80211/mesh_pathtbl.c
+++ b/net/mac80211/mesh_pathtbl.c
@@ -404,7 +404,6 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
404{ 404{
405 struct mesh_table *tbl; 405 struct mesh_table *tbl;
406 struct mesh_path *mpath, *new_mpath; 406 struct mesh_path *mpath, *new_mpath;
407 int ret;
408 407
409 if (ether_addr_equal(dst, sdata->vif.addr)) 408 if (ether_addr_equal(dst, sdata->vif.addr))
410 /* never add ourselves as neighbours */ 409 /* never add ourselves as neighbours */
@@ -422,25 +421,18 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
422 421
423 tbl = sdata->u.mesh.mesh_paths; 422 tbl = sdata->u.mesh.mesh_paths;
424 spin_lock_bh(&tbl->walk_lock); 423 spin_lock_bh(&tbl->walk_lock);
425 do { 424 mpath = rhashtable_lookup_get_insert_fast(&tbl->rhead,
426 ret = rhashtable_lookup_insert_fast(&tbl->rhead, 425 &new_mpath->rhash,
427 &new_mpath->rhash, 426 mesh_rht_params);
428 mesh_rht_params); 427 if (!mpath)
429 428 hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
430 if (ret == -EEXIST)
431 mpath = rhashtable_lookup_fast(&tbl->rhead,
432 dst,
433 mesh_rht_params);
434 else if (!ret)
435 hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
436 } while (unlikely(ret == -EEXIST && !mpath));
437 spin_unlock_bh(&tbl->walk_lock); 429 spin_unlock_bh(&tbl->walk_lock);
438 430
439 if (ret) { 431 if (mpath) {
440 kfree(new_mpath); 432 kfree(new_mpath);
441 433
442 if (ret != -EEXIST) 434 if (IS_ERR(mpath))
443 return ERR_PTR(ret); 435 return mpath;
444 436
445 new_mpath = mpath; 437 new_mpath = mpath;
446 } 438 }