public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Antonio Quartulli <a@unstable.cc>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Antonio Quartulli <a@unstable.cc>,
	Marek Lindner <mareklindner@neomailbox.ch>
Subject: [B.A.T.M.A.N.] [PATCH 12/21] batman-adv: Convert batadv_tvlv_container to kref
Date: Wed, 10 Feb 2016 23:57:18 +0800	[thread overview]
Message-ID: <1455119847-5862-13-git-send-email-a@unstable.cc> (raw)
In-Reply-To: <1455119847-5862-1-git-send-email-a@unstable.cc>

From: Sven Eckelmann <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>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Antonio Quartulli <a@unstable.cc>
---
 net/batman-adv/main.c  | 22 +++++++++++++++++-----
 net/batman-adv/types.h |  2 +-
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index a9b4f75db874..4b6c2589fa34 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -29,6 +29,7 @@
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/kernel.h>
+#include <linux/kref.h>
 #include <linux/list.h>
 #include <linux/lockdep.h>
 #include <linux/module.h>
@@ -670,14 +671,25 @@ static struct batadv_tvlv_handler
 }
 
 /**
+ * batadv_tvlv_container_release - release tvlv from lists and free
+ * @ref: kref pointer of the tvlv
+ */
+static void batadv_tvlv_container_release(struct kref *ref)
+{
+	struct batadv_tvlv_container *tvlv;
+
+	tvlv = container_of(ref, struct batadv_tvlv_container, refcount);
+	kfree(tvlv);
+}
+
+/**
  * batadv_tvlv_container_free_ref - decrement the tvlv container refcounter and
- *  possibly free it
+ *  possibly release it
  * @tvlv: the tvlv container to free
  */
 static void batadv_tvlv_container_free_ref(struct batadv_tvlv_container *tvlv)
 {
-	if (atomic_dec_and_test(&tvlv->refcount))
-		kfree(tvlv);
+	kref_put(&tvlv->refcount, batadv_tvlv_container_release);
 }
 
 /**
@@ -706,7 +718,7 @@ static struct batadv_tvlv_container
 		if (tvlv_tmp->tvlv_hdr.version != version)
 			continue;
 
-		if (!atomic_inc_not_zero(&tvlv_tmp->refcount))
+		if (!kref_get_unless_zero(&tvlv_tmp->refcount))
 			continue;
 
 		tvlv = tvlv_tmp;
@@ -814,7 +826,7 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
 
 	memcpy(tvlv_new + 1, tvlv_value, ntohs(tvlv_new->tvlv_hdr.len));
 	INIT_HLIST_NODE(&tvlv_new->list);
-	atomic_set(&tvlv_new->refcount, 1);
+	kref_init(&tvlv_new->refcount);
 
 	spin_lock_bh(&bat_priv->tvlv.container_list_lock);
 	tvlv_old = batadv_tvlv_container_get(bat_priv, type, version);
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 9df8f39e4785..c55925bb34af 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1266,7 +1266,7 @@ struct batadv_dat_candidate {
 struct batadv_tvlv_container {
 	struct hlist_node list;
 	struct batadv_tvlv_hdr tvlv_hdr;
-	atomic_t refcount;
+	struct kref refcount;
 };
 
 /**
-- 
2.7.1


  parent reply	other threads:[~2016-02-10 15:57 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-10 15:57 [B.A.T.M.A.N.] pull request [net-next]: batman-adv 20160210 Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 01/21] batman-adv: Drop reference to netdevice on last reference Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 02/21] batman-adv: add seqno maximum age and protection start flag parameters Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 03/21] batman-adv: Add lockdep assert for container_list_lock Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 04/21] batman-adv: Convert batadv_hardif_neigh_node to kref Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 05/21] batman-adv: Convert batadv_gw_node " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 06/21] batman-adv: Convert batadv_softif_vlan " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 07/21] batman-adv: Convert batadv_bla_backbone_gw " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 08/21] batman-adv: Convert batadv_bla_claim " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 09/21] batman-adv: Convert batadv_nc_node " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 10/21] batman-adv: Convert batadv_nc_path " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 11/21] batman-adv: Convert batadv_dat_entry " Antonio Quartulli
2016-02-10 15:57 ` Antonio Quartulli [this message]
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 13/21] batman-adv: Convert batadv_tvlv_handler " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 14/21] batman-adv: Convert batadv_tt_orig_list_entry " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 15/21] batman-adv: Convert batadv_neigh_ifinfo " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 16/21] batman-adv: Convert batadv_orig_ifinfo " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 17/21] batman-adv: Convert batadv_neigh_node " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 18/21] batman-adv: Convert batadv_hard_iface " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 19/21] batman-adv: Convert batadv_orig_node_vlan " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 20/21] batman-adv: Convert batadv_orig_node " Antonio Quartulli
2016-02-10 15:57 ` [B.A.T.M.A.N.] [PATCH 21/21] batman-adv: Convert batadv_tt_common_entry " Antonio Quartulli
2016-02-11  8:50 ` [B.A.T.M.A.N.] pull request [net-next]: batman-adv 20160210 David Miller

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=1455119847-5862-13-git-send-email-a@unstable.cc \
    --to=a@unstable.cc \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=mareklindner@neomailbox.ch \
    --cc=netdev@vger.kernel.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