public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH v2 22/30] batman-adv: Convert batadv_tt_orig_list_entry to kref
Date: Sun, 20 Dec 2015 14:18:02 +0100	[thread overview]
Message-ID: <1450617490-3544-22-git-send-email-sven@narfation.org> (raw)
In-Reply-To: <1450617490-3544-1-git-send-email-sven@narfation.org>

batman-adv uses a self-written reference implementation which is just based
on atomic_t. This is less obvious when reading the code than kref and
therefore increases the change that the reference counting will be missed.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
v2:
 - split patchset into fixes and kref migration to make it easier when the
   decision is made where each patch will be applied

 net/batman-adv/translation-table.c | 26 +++++++++++++++++---------
 net/batman-adv/types.h             |  2 +-
 2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 96c3577..bc18ab5 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -31,6 +31,7 @@
 #include <linux/jhash.h>
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
+#include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/lockdep.h>
 #include <linux/netdevice.h>
@@ -346,22 +347,28 @@ static void batadv_tt_global_size_dec(struct batadv_orig_node *orig_node,
 /**
  * batadv_tt_orig_list_entry_release - release  tt orig entry from lists and
  *  queue for free after rcu grace period
- * @orig_entry: tt orig entry to be free'd
+ * @ref: kref pointer of the tt orig entry
  */
-static void
-batadv_tt_orig_list_entry_release(struct batadv_tt_orig_list_entry *orig_entry)
+static void batadv_tt_orig_list_entry_release(struct kref *ref)
 {
+	struct batadv_tt_orig_list_entry *orig_entry;
+
+	orig_entry = container_of(ref, struct batadv_tt_orig_list_entry,
+				  refcount);
+
 	batadv_orig_node_free_ref(orig_entry->orig_node);
 	kfree_rcu(orig_entry, rcu);
 }
 
+/**
+ * batadv_tt_orig_list_entry_free_ref - decrement the tt orig entry refcounter
+ *  and possibly release it
+ * @orig_entry: tt orig entry to be free'd
+ */
 static void
 batadv_tt_orig_list_entry_free_ref(struct batadv_tt_orig_list_entry *orig_entry)
 {
-	if (!atomic_dec_and_test(&orig_entry->refcount))
-		return;
-
-	batadv_tt_orig_list_entry_release(orig_entry);
+	kref_put(&orig_entry->refcount, batadv_tt_orig_list_entry_release);
 }
 
 /**
@@ -1270,7 +1277,7 @@ batadv_tt_global_orig_entry_find(const struct batadv_tt_global_entry *entry,
 	hlist_for_each_entry_rcu(tmp_orig_entry, head, list) {
 		if (tmp_orig_entry->orig_node != orig_node)
 			continue;
-		if (!atomic_inc_not_zero(&tmp_orig_entry->refcount))
+		if (!kref_get_unless_zero(&tmp_orig_entry->refcount))
 			continue;
 
 		orig_entry = tmp_orig_entry;
@@ -1331,7 +1338,8 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,
 	batadv_tt_global_size_inc(orig_node, tt_global->common.vid);
 	orig_entry->orig_node = orig_node;
 	orig_entry->ttvn = ttvn;
-	atomic_set(&orig_entry->refcount, 2);
+	kref_init(&orig_entry->refcount);
+	kref_get(&orig_entry->refcount);
 
 	spin_lock_bh(&tt_global->list_lock);
 	hlist_add_head_rcu(&orig_entry->list,
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 60d304b..58ae09e 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1014,7 +1014,7 @@ struct batadv_tt_orig_list_entry {
 	struct batadv_orig_node *orig_node;
 	u8 ttvn;
 	struct hlist_node list;
-	atomic_t refcount;
+	struct kref refcount;
 	struct rcu_head rcu;
 };
 
-- 
2.6.4


  parent reply	other threads:[~2015-12-20 13:18 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-20 13:17 [B.A.T.M.A.N.] [PATCH v2 01/30] batman-adv: Fix list removal of batadv_hardif_neigh_node Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 02/30] batman-adv: Avoid recursive call_rcu for batadv_bla_claim Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 03/30] batman-adv: Avoid recursive call_rcu for batadv_nc_node Sven Eckelmann
2016-01-04 16:04   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 04/30] batman-adv: Drop immediate orig_node free function Sven Eckelmann
2016-01-04 16:32   ` Linus Lüssing
2016-01-04 16:47   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 05/30] batman-adv: Drop immediate batadv_orig_ifinfo " Sven Eckelmann
2016-01-04 18:59   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 06/30] batman-adv: Drop immediate batadv_neigh_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 07/30] batman-adv: Drop immediate batadv_hardif_neigh_node " Sven Eckelmann
2016-01-05  1:31   ` Linus Lüssing
2016-01-05  1:50     ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 08/30] batman-adv: Drop immediate neigh_ifinfo " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 09/30] batman-adv: Drop immediate batadv_hard_iface " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 10/30] batman-adv: Drop reference to netdevice on last reference Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 11/30] batman-adv: Add compatibility code for kref_get_unless_zero Sven Eckelmann
2015-12-31 23:14   ` [B.A.T.M.A.N.] [PATCH v3 " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 12/30] batman-adv: Convert batadv_hardif_neigh_node to kref Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 13/30] batman-adv: Convert batadv_gw_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 14/30] batman-adv: Convert batadv_softif_vlan " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 15/30] batman-adv: Convert batadv_bla_backbone_gw " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 16/30] batman-adv: Convert batadv_bla_claim " Sven Eckelmann
2016-01-05  4:43   ` Linus Lüssing
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 17/30] batman-adv: Convert batadv_nc_node " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 18/30] batman-adv: Convert batadv_nc_path " Sven Eckelmann
2015-12-20 13:17 ` [B.A.T.M.A.N.] [PATCH v2 19/30] batman-adv: Convert batadv_dat_entry " Sven Eckelmann
2016-01-05  4:45   ` Linus Lüssing
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 20/30] batman-adv: Convert batadv_tvlv_container " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 21/30] batman-adv: Convert batadv_tvlv_handler " Sven Eckelmann
2015-12-20 13:18 ` Sven Eckelmann [this message]
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 23/30] batman-adv: Convert batadv_neigh_ifinfo " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 24/30] batman-adv: Convert batadv_orig_ifinfo " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 25/30] batman-adv: Convert batadv_neigh_node " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 26/30] batman-adv: Convert batadv_hard_iface " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 27/30] batman-adv: Convert batadv_orig_node_vlan " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 28/30] batman-adv: Convert batadv_orig_node " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 29/30] batman-adv: Convert batadv_tt_common_entry " Sven Eckelmann
2015-12-20 13:18 ` [B.A.T.M.A.N.] [PATCH v2 30/30] batman-adv: Rename *_free_ref function to *_put Sven Eckelmann
2016-01-04 16:03 ` [B.A.T.M.A.N.] [PATCH v2 01/30] batman-adv: Fix list removal of batadv_hardif_neigh_node Linus Lüssing
2016-01-05  5:02 ` Linus Lüssing
2016-01-05  9:18   ` Sven Eckelmann

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=1450617490-3544-22-git-send-email-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /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