aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2015-06-21 08:45:14 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2015-08-24 18:12:23 -0400
commit2c72d655b04450056566bcbfe89c2427376b60b4 (patch)
tree79b4d9eaff924dea2776a3ac3758550d736dd819
parent7c26a53ba5e7e4bf2be3cb93f2fffaefccff2e3b (diff)
batman-adv: Annotate deleting functions with external lock via lockdep
Functions which use (h)list_del* are requiring correct locking when they operate on global lists. Most of the time the search in the list and the delete are done in the same function. All other cases should have it visible that they require a special lock to avoid race conditions. Lockdep asserts can be used to check these problem during runtime when the lockdep functionality is enabled. Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
-rw-r--r--net/batman-adv/main.c11
-rw-r--r--net/batman-adv/multicast.c13
-rw-r--r--net/batman-adv/network-coding.c4
-rw-r--r--net/batman-adv/translation-table.c2
4 files changed, 25 insertions, 5 deletions
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index d277ba724a86..50fc07b9d353 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -30,6 +30,7 @@
30#include <linux/ipv6.h> 30#include <linux/ipv6.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/lockdep.h>
33#include <linux/module.h> 34#include <linux/module.h>
34#include <linux/moduleparam.h> 35#include <linux/moduleparam.h>
35#include <linux/netdevice.h> 36#include <linux/netdevice.h>
@@ -737,13 +738,17 @@ static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
737/** 738/**
738 * batadv_tvlv_container_remove - remove tvlv container from the tvlv container 739 * batadv_tvlv_container_remove - remove tvlv container from the tvlv container
739 * list 740 * list
741 * @bat_priv: the bat priv with all the soft interface information
740 * @tvlv: the to be removed tvlv container 742 * @tvlv: the to be removed tvlv container
741 * 743 *
742 * Has to be called with the appropriate locks being acquired 744 * Has to be called with the appropriate locks being acquired
743 * (tvlv.container_list_lock). 745 * (tvlv.container_list_lock).
744 */ 746 */
745static void batadv_tvlv_container_remove(struct batadv_tvlv_container *tvlv) 747static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv,
748 struct batadv_tvlv_container *tvlv)
746{ 749{
750 lockdep_assert_held(&bat_priv->tvlv.handler_list_lock);
751
747 if (!tvlv) 752 if (!tvlv)
748 return; 753 return;
749 754
@@ -768,7 +773,7 @@ void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
768 773
769 spin_lock_bh(&bat_priv->tvlv.container_list_lock); 774 spin_lock_bh(&bat_priv->tvlv.container_list_lock);
770 tvlv = batadv_tvlv_container_get(bat_priv, type, version); 775 tvlv = batadv_tvlv_container_get(bat_priv, type, version);
771 batadv_tvlv_container_remove(tvlv); 776 batadv_tvlv_container_remove(bat_priv, tvlv);
772 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); 777 spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
773} 778}
774 779
@@ -807,7 +812,7 @@ void batadv_tvlv_container_register(struct batadv_priv *bat_priv,
807 812
808 spin_lock_bh(&bat_priv->tvlv.container_list_lock); 813 spin_lock_bh(&bat_priv->tvlv.container_list_lock);
809 tvlv_old = batadv_tvlv_container_get(bat_priv, type, version); 814 tvlv_old = batadv_tvlv_container_get(bat_priv, type, version);
810 batadv_tvlv_container_remove(tvlv_old); 815 batadv_tvlv_container_remove(bat_priv, tvlv_old);
811 hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list); 816 hlist_add_head(&tvlv_new->list, &bat_priv->tvlv.container_list);
812 spin_unlock_bh(&bat_priv->tvlv.container_list_lock); 817 spin_unlock_bh(&bat_priv->tvlv.container_list_lock);
813} 818}
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 2593f0fe0bad..410f34cf85c2 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -31,6 +31,7 @@
31#include <linux/ip.h> 31#include <linux/ip.h>
32#include <linux/ipv6.h> 32#include <linux/ipv6.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/lockdep.h>
34#include <linux/netdevice.h> 35#include <linux/netdevice.h>
35#include <linux/rculist.h> 36#include <linux/rculist.h>
36#include <linux/rcupdate.h> 37#include <linux/rcupdate.h>
@@ -103,15 +104,19 @@ static bool batadv_mcast_mla_is_duplicate(u8 *mcast_addr,
103 104
104/** 105/**
105 * batadv_mcast_mla_list_free - free a list of multicast addresses 106 * batadv_mcast_mla_list_free - free a list of multicast addresses
107 * @bat_priv: the bat priv with all the soft interface information
106 * @mcast_list: the list to free 108 * @mcast_list: the list to free
107 * 109 *
108 * Removes and frees all items in the given mcast_list. 110 * Removes and frees all items in the given mcast_list.
109 */ 111 */
110static void batadv_mcast_mla_list_free(struct hlist_head *mcast_list) 112static void batadv_mcast_mla_list_free(struct batadv_priv *bat_priv,
113 struct hlist_head *mcast_list)
111{ 114{
112 struct batadv_hw_addr *mcast_entry; 115 struct batadv_hw_addr *mcast_entry;
113 struct hlist_node *tmp; 116 struct hlist_node *tmp;
114 117
118 lockdep_assert_held(&bat_priv->tt.commit_lock);
119
115 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) { 120 hlist_for_each_entry_safe(mcast_entry, tmp, mcast_list, list) {
116 hlist_del(&mcast_entry->list); 121 hlist_del(&mcast_entry->list);
117 kfree(mcast_entry); 122 kfree(mcast_entry);
@@ -134,6 +139,8 @@ static void batadv_mcast_mla_tt_retract(struct batadv_priv *bat_priv,
134 struct batadv_hw_addr *mcast_entry; 139 struct batadv_hw_addr *mcast_entry;
135 struct hlist_node *tmp; 140 struct hlist_node *tmp;
136 141
142 lockdep_assert_held(&bat_priv->tt.commit_lock);
143
137 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list, 144 hlist_for_each_entry_safe(mcast_entry, tmp, &bat_priv->mcast.mla_list,
138 list) { 145 list) {
139 if (mcast_list && 146 if (mcast_list &&
@@ -164,6 +171,8 @@ static void batadv_mcast_mla_tt_add(struct batadv_priv *bat_priv,
164 struct batadv_hw_addr *mcast_entry; 171 struct batadv_hw_addr *mcast_entry;
165 struct hlist_node *tmp; 172 struct hlist_node *tmp;
166 173
174 lockdep_assert_held(&bat_priv->tt.commit_lock);
175
167 if (!mcast_list) 176 if (!mcast_list)
168 return; 177 return;
169 178
@@ -268,7 +277,7 @@ update:
268 batadv_mcast_mla_tt_add(bat_priv, &mcast_list); 277 batadv_mcast_mla_tt_add(bat_priv, &mcast_list);
269 278
270out: 279out:
271 batadv_mcast_mla_list_free(&mcast_list); 280 batadv_mcast_mla_list_free(bat_priv, &mcast_list);
272} 281}
273 282
274/** 283/**
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index ccfe5d86b106..f5276be2c77c 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -586,6 +586,8 @@ static bool batadv_nc_sniffed_purge(struct batadv_priv *bat_priv,
586 unsigned long timeout = bat_priv->nc.max_buffer_time; 586 unsigned long timeout = bat_priv->nc.max_buffer_time;
587 bool res = false; 587 bool res = false;
588 588
589 lockdep_assert_held(&nc_path->packet_list_lock);
590
589 /* Packets are added to tail, so the remaining packets did not time 591 /* Packets are added to tail, so the remaining packets did not time
590 * out and we can stop processing the current queue 592 * out and we can stop processing the current queue
591 */ 593 */
@@ -622,6 +624,8 @@ static bool batadv_nc_fwd_flush(struct batadv_priv *bat_priv,
622{ 624{
623 unsigned long timeout = bat_priv->nc.max_fwd_delay; 625 unsigned long timeout = bat_priv->nc.max_fwd_delay;
624 626
627 lockdep_assert_held(&nc_path->packet_list_lock);
628
625 /* Packets are added to tail, so the remaining packets did not time 629 /* Packets are added to tail, so the remaining packets did not time
626 * out and we can stop processing the current queue 630 * out and we can stop processing the current queue
627 */ 631 */
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 734b456efaf4..79cee7b771dc 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -1672,6 +1672,8 @@ static void
1672_batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry, 1672_batadv_tt_global_del_orig_entry(struct batadv_tt_global_entry *tt_global_entry,
1673 struct batadv_tt_orig_list_entry *orig_entry) 1673 struct batadv_tt_orig_list_entry *orig_entry)
1674{ 1674{
1675 lockdep_assert_held(&tt_global_entry->list_lock);
1676
1675 batadv_tt_global_size_dec(orig_entry->orig_node, 1677 batadv_tt_global_size_dec(orig_entry->orig_node,
1676 tt_global_entry->common.vid); 1678 tt_global_entry->common.vid);
1677 atomic_dec(&tt_global_entry->orig_list_count); 1679 atomic_dec(&tt_global_entry->orig_list_count);