batman-adv: Protect global TQ window with a spinlock
authorLinus Lüssing <linus.luessing@web.de>
Mon, 14 Mar 2011 22:43:40 +0000 (22:43 +0000)
committerSven Eckelmann <sven@narfation.org>
Sun, 17 Apr 2011 19:11:01 +0000 (21:11 +0200)
Signed-off-by: Linus Lüssing <linus.luessing@web.de>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
net/batman-adv/originator.c
net/batman-adv/routing.c
net/batman-adv/types.h

index b4cfe36861551bdde8439cc6812ba358ed360bed..5b8fe32043dad807f8a17a12b0fa38a0a6fe94da 100644 (file)
@@ -102,6 +102,7 @@ struct neigh_node *create_neighbor(struct orig_node *orig_node,
 
        INIT_HLIST_NODE(&neigh_node->list);
        INIT_LIST_HEAD(&neigh_node->bonding_list);
+       spin_lock_init(&neigh_node->tq_lock);
 
        memcpy(neigh_node->addr, neigh, ETH_ALEN);
        neigh_node->orig_node = orig_neigh_node;
index b7d43caaa9c8644460ff091ea1b7943c3d253e15..f6c64224697248fcde44bb05305f141000927897 100644 (file)
@@ -415,10 +415,12 @@ static void update_orig(struct bat_priv *bat_priv,
                if (is_duplicate)
                        continue;
 
+               spin_lock_bh(&tmp_neigh_node->tq_lock);
                ring_buffer_set(tmp_neigh_node->tq_recv,
                                &tmp_neigh_node->tq_index, 0);
                tmp_neigh_node->tq_avg =
                        ring_buffer_avg(tmp_neigh_node->tq_recv);
+               spin_unlock_bh(&tmp_neigh_node->tq_lock);
        }
 
        if (!neigh_node) {
@@ -443,10 +445,12 @@ static void update_orig(struct bat_priv *bat_priv,
        orig_node->flags = batman_packet->flags;
        neigh_node->last_valid = jiffies;
 
+       spin_lock_bh(&neigh_node->tq_lock);
        ring_buffer_set(neigh_node->tq_recv,
                        &neigh_node->tq_index,
                        batman_packet->tq);
        neigh_node->tq_avg = ring_buffer_avg(neigh_node->tq_recv);
+       spin_unlock_bh(&neigh_node->tq_lock);
 
        if (!is_duplicate) {
                orig_node->last_ttl = batman_packet->ttl;
index 1854cbb4c1b6d777b6e5c4f277541aeabdb63c5c..091476df4f0efd231aca6b2ebb28a9d3bfe9fc92 100644 (file)
@@ -125,6 +125,7 @@ struct neigh_node {
        struct rcu_head rcu;
        struct orig_node *orig_node;
        struct hard_iface *if_incoming;
+       spinlock_t tq_lock;     /* protects: tq_recv, tq_index */
 };