summaryrefslogtreecommitdiff
path: root/net/batman-adv/originator.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2010-12-12 21:57:10 +0000
committerMarek Lindner <lindner_marek@yahoo.de>2011-03-05 12:49:52 +0100
commita8e7f4bc38c4a90ee308cd7f1f8604f71db59d05 (patch)
treeeaad8069534691aaa06b316ce42fbeb81f380b20 /net/batman-adv/originator.c
parent8d689218568174955129d0f0e9e4370a391b3609 (diff)
batman-adv: protect neighbor nodes with reference counters
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/originator.c')
-rw-r--r--net/batman-adv/originator.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 54863c9385de..b1b1773afa0b 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -59,9 +59,18 @@ err:
return 0;
}
-struct neigh_node *
-create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
- uint8_t *neigh, struct batman_if *if_incoming)
+void neigh_node_free_ref(struct kref *refcount)
+{
+ struct neigh_node *neigh_node;
+
+ neigh_node = container_of(refcount, struct neigh_node, refcount);
+ kfree(neigh_node);
+}
+
+struct neigh_node *create_neighbor(struct orig_node *orig_node,
+ struct orig_node *orig_neigh_node,
+ uint8_t *neigh,
+ struct batman_if *if_incoming)
{
struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
struct neigh_node *neigh_node;
@@ -78,6 +87,7 @@ create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node,
memcpy(neigh_node->addr, neigh, ETH_ALEN);
neigh_node->orig_node = orig_neigh_node;
neigh_node->if_incoming = if_incoming;
+ kref_init(&neigh_node->refcount);
list_add_tail(&neigh_node->list, &orig_node->neigh_list);
return neigh_node;
@@ -95,7 +105,7 @@ static void free_orig_node(void *data, void *arg)
neigh_node = list_entry(list_pos, struct neigh_node, list);
list_del(list_pos);
- kfree(neigh_node);
+ kref_put(&neigh_node->refcount, neigh_node_free_ref);
}
frag_list_free(&orig_node->frag_list);
@@ -216,7 +226,7 @@ static bool purge_orig_neighbors(struct bat_priv *bat_priv,
neigh_purged = true;
list_del(list_pos);
- kfree(neigh_node);
+ kref_put(&neigh_node->refcount, neigh_node_free_ref);
} else {
if ((!*best_neigh_node) ||
(neigh_node->tq_avg > (*best_neigh_node)->tq_avg))