All of lore.kernel.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 14/30] batman-adv: Convert batadv_softif_vlan to kref
Date: Sun, 20 Dec 2015 14:17:54 +0100	[thread overview]
Message-ID: <1450617490-3544-14-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/soft-interface.c | 31 ++++++++++++++++++++++---------
 net/batman-adv/sysfs.c          |  3 ++-
 net/batman-adv/types.h          |  2 +-
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 6c65de9..8ae61ac 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -30,6 +30,7 @@
 #include <linux/if_vlan.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>
@@ -478,6 +479,24 @@ out:
 }
 
 /**
+ * batadv_softif_vlan_release - release vlan from lists and queue for free after
+ *  rcu grace period
+ * @ref: kref pointer of the vlan object
+ */
+static void batadv_softif_vlan_release(struct kref *ref)
+{
+	struct batadv_softif_vlan *vlan;
+
+	vlan = container_of(ref, struct batadv_softif_vlan, refcount);
+
+	spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
+	hlist_del_rcu(&vlan->list);
+	spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
+
+	kfree_rcu(vlan, rcu);
+}
+
+/**
  * batadv_softif_vlan_free_ref - decrease the vlan object refcounter and
  *  possibly free it
  * @vlan: the vlan object to release
@@ -487,13 +506,7 @@ void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *vlan)
 	if (!vlan)
 		return;
 
-	if (atomic_dec_and_test(&vlan->refcount)) {
-		spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
-		hlist_del_rcu(&vlan->list);
-		spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
-
-		kfree_rcu(vlan, rcu);
-	}
+	kref_put(&vlan->refcount, batadv_softif_vlan_release);
 }
 
 /**
@@ -514,7 +527,7 @@ struct batadv_softif_vlan *batadv_softif_vlan_get(struct batadv_priv *bat_priv,
 		if (vlan_tmp->vid != vid)
 			continue;
 
-		if (!atomic_inc_not_zero(&vlan_tmp->refcount))
+		if (!kref_get_unless_zero(&vlan_tmp->refcount))
 			continue;
 
 		vlan = vlan_tmp;
@@ -549,7 +562,7 @@ int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
 
 	vlan->bat_priv = bat_priv;
 	vlan->vid = vid;
-	atomic_set(&vlan->refcount, 1);
+	kref_init(&vlan->refcount);
 
 	atomic_set(&vlan->ap_isolation, 0);
 
diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c
index f38d7b7..4f578ac 100644
--- a/net/batman-adv/sysfs.c
+++ b/net/batman-adv/sysfs.c
@@ -25,6 +25,7 @@
 #include <linux/fs.h>
 #include <linux/if.h>
 #include <linux/if_vlan.h>
+#include <linux/kref.h>
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/printk.h>
@@ -97,7 +98,7 @@ batadv_kobj_to_vlan(struct batadv_priv *bat_priv, struct kobject *obj)
 		if (vlan_tmp->kobj != obj)
 			continue;
 
-		if (!atomic_inc_not_zero(&vlan_tmp->refcount))
+		if (!kref_get_unless_zero(&vlan_tmp->refcount))
 			continue;
 
 		vlan = vlan_tmp;
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 0b3cbdb..c6c3f0f 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -746,7 +746,7 @@ struct batadv_softif_vlan {
 	atomic_t ap_isolation;		/* boolean */
 	struct batadv_vlan_tt tt;
 	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:17 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 ` Sven Eckelmann [this message]
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 ` [B.A.T.M.A.N.] [PATCH v2 22/30] batman-adv: Convert batadv_tt_orig_list_entry " Sven Eckelmann
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-14-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.