linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herbert Xu <herbert@gondor.apana.org.au>
To: David Miller <davem@davemloft.net>,
	johannes@sipsolutions.net, linux-wireless@vger.kernel.org,
	netdev@vger.kernel.org, j@w1.fi, tgraf@suug.ch,
	johannes.berg@intel.com
Subject: [PATCH 3/4] mac80211: Use rhashtable_lookup_get_insert_fast instead of racy code
Date: Wed, 13 Feb 2019 22:39:13 +0800	[thread overview]
Message-ID: <E1gtvgv-0006bd-7B@gondobar> (raw)
In-Reply-To: 20190213143853.labj6zdcsoupkris@gondor.apana.org.au

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>
---

 net/mac80211/mesh_pathtbl.c |   31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/net/mac80211/mesh_pathtbl.c b/net/mac80211/mesh_pathtbl.c
index db5a1aef22db..8902395e406e 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,
 {
 	struct mesh_table *tbl;
 	struct mesh_path *mpath, *new_mpath;
-	int ret;
 
 	if (ether_addr_equal(dst, sdata->vif.addr))
 		/* never add ourselves as neighbours */
@@ -422,32 +421,22 @@ struct mesh_path *mesh_path_add(struct ieee80211_sub_if_data *sdata,
 
 	tbl = sdata->u.mesh.mesh_paths;
 	spin_lock_bh(&tbl->walk_lock);
-	do {
-		ret = rhashtable_lookup_insert_fast(&tbl->rhead,
-						    &new_mpath->rhash,
-						    mesh_rht_params);
-
-		if (ret == -EEXIST)
-			mpath = rhashtable_lookup_fast(&tbl->rhead,
-						       dst,
-						       mesh_rht_params);
-		else if (!ret)
-			hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
-	} while (unlikely(ret == -EEXIST && !mpath));
+	mpath = rhashtable_lookup_get_insert_fast(&tbl->rhead,
+						  &new_mpath->rhash,
+						  mesh_rht_params);
+	if (!mpath)
+		hlist_add_head(&new_mpath->walk_list, &tbl->walk_head);
 	spin_unlock_bh(&tbl->walk_lock);
 
-	if (ret)
+	if (mpath) {
 		kfree(new_mpath);
 
-	if (ret != -EEXIST)
-		return ERR_PTR(ret);
+		if (IS_ERR(mpath))
+			return mpath;
 
-	/* At this point either new_mpath was added, or we found a
-	 * matching entry already in the table; in the latter case
-	 * free the unnecessary new entry.
-	 */
-	if (ret == -EEXIST)
 		new_mpath = mpath;
+	}
+
 	sdata->u.mesh.mesh_paths_generation++;
 	return new_mpath;
 }

  parent reply	other threads:[~2019-02-13 14:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-13  5:05 [PATCH 0/2] mac80211: Fix incorrect usage of rhashtable walk API Herbert Xu
2019-02-13  5:16 ` [PATCH 1/2] mac80211: Use linked list instead of rhashtable walk for mesh tables Herbert Xu
2019-02-13 13:47   ` Herbert Xu
2019-02-13  5:16 ` [PATCH 2/2] mac80211: Free mpath object when rhashtable insertion fails Herbert Xu
2019-02-14  5:52   ` Dan Carpenter
2019-02-13  5:25 ` [PATCH] mac80211: Use rhashtable_lookup_get_insert_fast instead of racy code Herbert Xu
2019-02-13  5:34 ` [PATCH] rhashtable: Remove obsolete rhashtable_walk_init function Herbert Xu
     [not found]   ` <201902131934.29Pw8ywP%fengguang.wu@intel.com>
2019-02-13 13:41     ` Herbert Xu
2019-02-13 14:38 ` [v2 PATCH 0/4] mac80211: Fix incorrect usage of rhashtable walk API Herbert Xu
2019-02-13 14:39   ` [PATCH 1/4] mac80211: Use linked list instead of rhashtable walk for mesh tables Herbert Xu
2019-02-13 14:39   ` [PATCH 2/4] mac80211: Free mpath object when rhashtable insertion fails Herbert Xu
2019-02-13 15:04     ` Johannes Berg
2019-02-14  9:41       ` Herbert Xu
2019-02-14 14:04       ` Herbert Xu
2019-02-13 14:39   ` Herbert Xu [this message]
2019-02-13 14:39   ` [PATCH 4/4] rhashtable: Remove obsolete rhashtable_walk_init function Herbert Xu
2019-02-13 14:55   ` [v2 PATCH 0/4] mac80211: Fix incorrect usage of rhashtable walk API Johannes Berg
2019-02-14 14:02   ` [v3 " Herbert Xu
2019-02-14 14:03     ` [PATCH 1/4] mac80211: Use linked list instead of rhashtable walk for mesh tables Herbert Xu
2019-02-14 14:03     ` [PATCH 2/4] mac80211: Free mpath object when rhashtable insertion fails Herbert Xu
2019-02-14 14:03     ` [PATCH 3/4] mac80211: Use rhashtable_lookup_get_insert_fast instead of racy code Herbert Xu
2019-02-14 14:03     ` [PATCH 4/4] rhashtable: Remove obsolete rhashtable_walk_init function Herbert Xu
2019-02-15 12:21     ` [v3 PATCH 0/4] mac80211: Fix incorrect usage of rhashtable walk API Johannes Berg
2019-02-18 10:25       ` Herbert Xu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1gtvgv-0006bd-7B@gondobar \
    --to=herbert@gondor.apana.org.au \
    --cc=davem@davemloft.net \
    --cc=j@w1.fi \
    --cc=johannes.berg@intel.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tgraf@suug.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).