The following commit has been merged in the master branch: commit 381a4eadfe6c330bac0ebc18120fd1114d2b948e Author: Marek Lindner lindner_marek@yahoo.de Date: Sat Oct 9 11:44:41 2010 +0000
batman-adv: convert gw_node custom refcounting to kref functions
Signed-off-by: Marek Lindner lindner_marek@yahoo.de
diff --git a/gateway_client.c b/gateway_client.c index e1264ba..d275560 100644 --- a/gateway_client.c +++ b/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/types.h b/types.h index da7d1e3..9c13862 100644 --- a/types.h +++ b/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; };
/**