[1/4] batman-adv: convert gw_node custom refcounting to kref functions

Message ID 1285848524-13469-2-git-send-email-lindner_marek@yahoo.de
State Accepted, archived
Headers

Commit Message

Marek Lindner Sept. 30, 2010, 12:08 p.m. UTC
  Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 batman-adv/gateway_client.c |   24 ++++++++++--------------
 batman-adv/types.h          |    2 +-
 2 files changed, 11 insertions(+), 15 deletions(-)
  

Patch

diff --git a/batman-adv/gateway_client.c b/batman-adv/gateway_client.c
index e1264ba..d275560 100644
--- a/batman-adv/gateway_client.c
+++ b/batman-adv/gateway_client.c
@@ -28,15 +28,12 @@ 
 #include <linux/udp.h>
 #include <linux/if_vlan.h>
 
-static void gw_node_hold(struct gw_node *gw_node)
+static void gw_node_free_ref(struct kref *refcount)
 {
-	atomic_inc(&gw_node->refcnt);
-}
+	struct gw_node *gw_node;
 
-static void gw_node_put(struct gw_node *gw_node)
-{
-	if (atomic_dec_and_test(&gw_node->refcnt))
-		kfree(gw_node);
+	gw_node = container_of(refcount, struct gw_node, refcount);
+	kfree(gw_node);
 }
 
 void *gw_get_selected(struct bat_priv *bat_priv)
@@ -56,7 +53,7 @@  void gw_deselect(struct bat_priv *bat_priv)
 	bat_priv->curr_gw = NULL;
 
 	if (gw_node)
-		gw_node_put(gw_node);
+		kref_put(&gw_node->refcount, gw_node_free_ref);
 }
 
 static struct gw_node *gw_select(struct bat_priv *bat_priv,
@@ -65,7 +62,7 @@  static struct gw_node *gw_select(struct bat_priv *bat_priv,
 	struct gw_node *curr_gw_node = bat_priv->curr_gw;
 
 	if (new_gw_node)
-		gw_node_hold(new_gw_node);
+		kref_get(&new_gw_node->refcount);
 
 	bat_priv->curr_gw = new_gw_node;
 	return curr_gw_node;
@@ -176,7 +173,7 @@  void gw_election(struct bat_priv *bat_priv)
 
 	/* the kfree() has to be outside of the rcu lock */
 	if (old_gw_node)
-		gw_node_put(old_gw_node);
+		kref_put(&old_gw_node->refcount, gw_node_free_ref);
 }
 
 void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node)
@@ -238,8 +235,7 @@  static void gw_node_add(struct bat_priv *bat_priv,
 	memset(gw_node, 0, sizeof(struct gw_node));
 	INIT_HLIST_NODE(&gw_node->list);
 	gw_node->orig_node = orig_node;
-	atomic_set(&gw_node->refcnt, 0);
-	gw_node_hold(gw_node);
+	kref_init(&gw_node->refcount);
 
 	spin_lock_irqsave(&bat_priv->gw_list_lock, flags);
 	hlist_add_head_rcu(&gw_node->list, &bat_priv->gw_list);
@@ -319,7 +315,7 @@  void gw_node_purge_deleted(struct bat_priv *bat_priv)
 
 			hlist_del_rcu(&gw_node->list);
 			synchronize_rcu();
-			gw_node_put(gw_node);
+			kref_put(&gw_node->refcount, gw_node_free_ref);
 		}
 	}
 
@@ -338,7 +334,7 @@  void gw_node_list_free(struct bat_priv *bat_priv)
 				 &bat_priv->gw_list, list) {
 		hlist_del_rcu(&gw_node->list);
 		synchronize_rcu();
-		gw_node_put(gw_node);
+		kref_put(&gw_node->refcount, gw_node_free_ref);
 	}
 
 	gw_deselect(bat_priv);
diff --git a/batman-adv/types.h b/batman-adv/types.h
index a609100..f5d29e6 100644
--- a/batman-adv/types.h
+++ b/batman-adv/types.h
@@ -96,7 +96,7 @@  struct gw_node {
 	struct hlist_node list;
 	struct orig_node *orig_node;
 	unsigned long deleted;
-	atomic_t refcnt;
+	struct kref refcount;
 };
 
 /**