aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/originator.c
diff options
context:
space:
mode:
authorSasha Levin <sasha.levin@oracle.com>2013-02-27 20:06:00 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-27 22:10:24 -0500
commitb67bfe0d42cac56c512dd5da4b1b347a23f4b70a (patch)
tree3d465aea12b97683f26ffa38eba8744469de9997 /net/batman-adv/originator.c
parent1e142b29e210b5dfb2deeb6ce2210b60af16d2a6 (diff)
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived list_for_each_entry(pos, head, member) The hlist ones were greedy and wanted an extra parameter: hlist_for_each_entry(tpos, pos, head, member) Why did they need an extra pos parameter? I'm not quite sure. Not only they don't really need it, it also prevents the iterator from looking exactly like the list iterator, which is unfortunate. Besides the semantic patch, there was some manual work required: - Fix up the actual hlist iterators in linux/list.h - Fix up the declaration of other iterators based on the hlist ones. - A very small amount of places were using the 'node' parameter, this was modified to use 'obj->member' instead. - Coccinelle didn't handle the hlist_for_each_entry_safe iterator properly, so those had to be fixed up manually. The semantic patch which is mostly the work of Peter Senna Tschudin is here: @@ iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host; type T; expression a,c,d,e; identifier b; statement S; @@ -T b; <+... when != b ( hlist_for_each_entry(a, - b, c, d) S | hlist_for_each_entry_continue(a, - b, c) S | hlist_for_each_entry_from(a, - b, c) S | hlist_for_each_entry_rcu(a, - b, c, d) S | hlist_for_each_entry_rcu_bh(a, - b, c, d) S | hlist_for_each_entry_continue_rcu_bh(a, - b, c) S | for_each_busy_worker(a, c, - b, d) S | ax25_uid_for_each(a, - b, c) S | ax25_for_each(a, - b, c) S | inet_bind_bucket_for_each(a, - b, c) S | sctp_for_each_hentry(a, - b, c) S | sk_for_each(a, - b, c) S | sk_for_each_rcu(a, - b, c) S | sk_for_each_from -(a, b) +(a) S + sk_for_each_from(a) S | sk_for_each_safe(a, - b, c, d) S | sk_for_each_bound(a, - b, c) S | hlist_for_each_entry_safe(a, - b, c, d, e) S | hlist_for_each_entry_continue_rcu(a, - b, c) S | nr_neigh_for_each(a, - b, c) S | nr_neigh_for_each_safe(a, - b, c, d) S | nr_node_for_each(a, - b, c) S | nr_node_for_each_safe(a, - b, c, d) S | - for_each_gfn_sp(a, c, d, b) S + for_each_gfn_sp(a, c, d) S | - for_each_gfn_indirect_valid_sp(a, c, d, b) S + for_each_gfn_indirect_valid_sp(a, c, d) S | for_each_host(a, - b, c) S | for_each_host_safe(a, - b, c, d) S | for_each_mesh_entry(a, - b, c, d) S ) ...+> [akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c] [akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c] [akpm@linux-foundation.org: checkpatch fixes] [akpm@linux-foundation.org: fix warnings] [akpm@linux-foudnation.org: redo intrusive kvm changes] Tested-by: Peter Senna Tschudin <peter.senna@gmail.com> Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com> Cc: Wu Fengguang <fengguang.wu@intel.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Gleb Natapov <gleb@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/batman-adv/originator.c')
-rw-r--r--net/batman-adv/originator.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 457ea445217c..96fb80b724dc 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -118,7 +118,7 @@ out:
118 118
119static void batadv_orig_node_free_rcu(struct rcu_head *rcu) 119static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
120{ 120{
121 struct hlist_node *node, *node_tmp; 121 struct hlist_node *node_tmp;
122 struct batadv_neigh_node *neigh_node, *tmp_neigh_node; 122 struct batadv_neigh_node *neigh_node, *tmp_neigh_node;
123 struct batadv_orig_node *orig_node; 123 struct batadv_orig_node *orig_node;
124 124
@@ -134,7 +134,7 @@ static void batadv_orig_node_free_rcu(struct rcu_head *rcu)
134 } 134 }
135 135
136 /* for all neighbors towards this originator ... */ 136 /* for all neighbors towards this originator ... */
137 hlist_for_each_entry_safe(neigh_node, node, node_tmp, 137 hlist_for_each_entry_safe(neigh_node, node_tmp,
138 &orig_node->neigh_list, list) { 138 &orig_node->neigh_list, list) {
139 hlist_del_rcu(&neigh_node->list); 139 hlist_del_rcu(&neigh_node->list);
140 batadv_neigh_node_free_ref(neigh_node); 140 batadv_neigh_node_free_ref(neigh_node);
@@ -161,7 +161,7 @@ void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node)
161void batadv_originator_free(struct batadv_priv *bat_priv) 161void batadv_originator_free(struct batadv_priv *bat_priv)
162{ 162{
163 struct batadv_hashtable *hash = bat_priv->orig_hash; 163 struct batadv_hashtable *hash = bat_priv->orig_hash;
164 struct hlist_node *node, *node_tmp; 164 struct hlist_node *node_tmp;
165 struct hlist_head *head; 165 struct hlist_head *head;
166 spinlock_t *list_lock; /* spinlock to protect write access */ 166 spinlock_t *list_lock; /* spinlock to protect write access */
167 struct batadv_orig_node *orig_node; 167 struct batadv_orig_node *orig_node;
@@ -179,9 +179,9 @@ void batadv_originator_free(struct batadv_priv *bat_priv)
179 list_lock = &hash->list_locks[i]; 179 list_lock = &hash->list_locks[i];
180 180
181 spin_lock_bh(list_lock); 181 spin_lock_bh(list_lock);
182 hlist_for_each_entry_safe(orig_node, node, node_tmp, 182 hlist_for_each_entry_safe(orig_node, node_tmp,
183 head, hash_entry) { 183 head, hash_entry) {
184 hlist_del_rcu(node); 184 hlist_del_rcu(&orig_node->hash_entry);
185 batadv_orig_node_free_ref(orig_node); 185 batadv_orig_node_free_ref(orig_node);
186 } 186 }
187 spin_unlock_bh(list_lock); 187 spin_unlock_bh(list_lock);
@@ -274,7 +274,7 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
274 struct batadv_orig_node *orig_node, 274 struct batadv_orig_node *orig_node,
275 struct batadv_neigh_node **best_neigh_node) 275 struct batadv_neigh_node **best_neigh_node)
276{ 276{
277 struct hlist_node *node, *node_tmp; 277 struct hlist_node *node_tmp;
278 struct batadv_neigh_node *neigh_node; 278 struct batadv_neigh_node *neigh_node;
279 bool neigh_purged = false; 279 bool neigh_purged = false;
280 unsigned long last_seen; 280 unsigned long last_seen;
@@ -285,7 +285,7 @@ batadv_purge_orig_neighbors(struct batadv_priv *bat_priv,
285 spin_lock_bh(&orig_node->neigh_list_lock); 285 spin_lock_bh(&orig_node->neigh_list_lock);
286 286
287 /* for all neighbors towards this originator ... */ 287 /* for all neighbors towards this originator ... */
288 hlist_for_each_entry_safe(neigh_node, node, node_tmp, 288 hlist_for_each_entry_safe(neigh_node, node_tmp,
289 &orig_node->neigh_list, list) { 289 &orig_node->neigh_list, list) {
290 last_seen = neigh_node->last_seen; 290 last_seen = neigh_node->last_seen;
291 if_incoming = neigh_node->if_incoming; 291 if_incoming = neigh_node->if_incoming;
@@ -348,7 +348,7 @@ static bool batadv_purge_orig_node(struct batadv_priv *bat_priv,
348static void _batadv_purge_orig(struct batadv_priv *bat_priv) 348static void _batadv_purge_orig(struct batadv_priv *bat_priv)
349{ 349{
350 struct batadv_hashtable *hash = bat_priv->orig_hash; 350 struct batadv_hashtable *hash = bat_priv->orig_hash;
351 struct hlist_node *node, *node_tmp; 351 struct hlist_node *node_tmp;
352 struct hlist_head *head; 352 struct hlist_head *head;
353 spinlock_t *list_lock; /* spinlock to protect write access */ 353 spinlock_t *list_lock; /* spinlock to protect write access */
354 struct batadv_orig_node *orig_node; 354 struct batadv_orig_node *orig_node;
@@ -363,13 +363,13 @@ static void _batadv_purge_orig(struct batadv_priv *bat_priv)
363 list_lock = &hash->list_locks[i]; 363 list_lock = &hash->list_locks[i];
364 364
365 spin_lock_bh(list_lock); 365 spin_lock_bh(list_lock);
366 hlist_for_each_entry_safe(orig_node, node, node_tmp, 366 hlist_for_each_entry_safe(orig_node, node_tmp,
367 head, hash_entry) { 367 head, hash_entry) {
368 if (batadv_purge_orig_node(bat_priv, orig_node)) { 368 if (batadv_purge_orig_node(bat_priv, orig_node)) {
369 if (orig_node->gw_flags) 369 if (orig_node->gw_flags)
370 batadv_gw_node_delete(bat_priv, 370 batadv_gw_node_delete(bat_priv,
371 orig_node); 371 orig_node);
372 hlist_del_rcu(node); 372 hlist_del_rcu(&orig_node->hash_entry);
373 batadv_orig_node_free_ref(orig_node); 373 batadv_orig_node_free_ref(orig_node);
374 continue; 374 continue;
375 } 375 }
@@ -408,7 +408,6 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
408 struct net_device *net_dev = (struct net_device *)seq->private; 408 struct net_device *net_dev = (struct net_device *)seq->private;
409 struct batadv_priv *bat_priv = netdev_priv(net_dev); 409 struct batadv_priv *bat_priv = netdev_priv(net_dev);
410 struct batadv_hashtable *hash = bat_priv->orig_hash; 410 struct batadv_hashtable *hash = bat_priv->orig_hash;
411 struct hlist_node *node, *node_tmp;
412 struct hlist_head *head; 411 struct hlist_head *head;
413 struct batadv_hard_iface *primary_if; 412 struct batadv_hard_iface *primary_if;
414 struct batadv_orig_node *orig_node; 413 struct batadv_orig_node *orig_node;
@@ -434,7 +433,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
434 head = &hash->table[i]; 433 head = &hash->table[i];
435 434
436 rcu_read_lock(); 435 rcu_read_lock();
437 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 436 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
438 neigh_node = batadv_orig_node_get_router(orig_node); 437 neigh_node = batadv_orig_node_get_router(orig_node);
439 if (!neigh_node) 438 if (!neigh_node)
440 continue; 439 continue;
@@ -453,7 +452,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
453 neigh_node->addr, 452 neigh_node->addr,
454 neigh_node->if_incoming->net_dev->name); 453 neigh_node->if_incoming->net_dev->name);
455 454
456 hlist_for_each_entry_rcu(neigh_node_tmp, node_tmp, 455 hlist_for_each_entry_rcu(neigh_node_tmp,
457 &orig_node->neigh_list, list) { 456 &orig_node->neigh_list, list) {
458 seq_printf(seq, " %pM (%3i)", 457 seq_printf(seq, " %pM (%3i)",
459 neigh_node_tmp->addr, 458 neigh_node_tmp->addr,
@@ -511,7 +510,6 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
511{ 510{
512 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 511 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
513 struct batadv_hashtable *hash = bat_priv->orig_hash; 512 struct batadv_hashtable *hash = bat_priv->orig_hash;
514 struct hlist_node *node;
515 struct hlist_head *head; 513 struct hlist_head *head;
516 struct batadv_orig_node *orig_node; 514 struct batadv_orig_node *orig_node;
517 uint32_t i; 515 uint32_t i;
@@ -524,7 +522,7 @@ int batadv_orig_hash_add_if(struct batadv_hard_iface *hard_iface,
524 head = &hash->table[i]; 522 head = &hash->table[i];
525 523
526 rcu_read_lock(); 524 rcu_read_lock();
527 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 525 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
528 spin_lock_bh(&orig_node->ogm_cnt_lock); 526 spin_lock_bh(&orig_node->ogm_cnt_lock);
529 ret = batadv_orig_node_add_if(orig_node, max_if_num); 527 ret = batadv_orig_node_add_if(orig_node, max_if_num);
530 spin_unlock_bh(&orig_node->ogm_cnt_lock); 528 spin_unlock_bh(&orig_node->ogm_cnt_lock);
@@ -595,7 +593,6 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
595{ 593{
596 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); 594 struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
597 struct batadv_hashtable *hash = bat_priv->orig_hash; 595 struct batadv_hashtable *hash = bat_priv->orig_hash;
598 struct hlist_node *node;
599 struct hlist_head *head; 596 struct hlist_head *head;
600 struct batadv_hard_iface *hard_iface_tmp; 597 struct batadv_hard_iface *hard_iface_tmp;
601 struct batadv_orig_node *orig_node; 598 struct batadv_orig_node *orig_node;
@@ -609,7 +606,7 @@ int batadv_orig_hash_del_if(struct batadv_hard_iface *hard_iface,
609 head = &hash->table[i]; 606 head = &hash->table[i];
610 607
611 rcu_read_lock(); 608 rcu_read_lock();
612 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { 609 hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
613 spin_lock_bh(&orig_node->ogm_cnt_lock); 610 spin_lock_bh(&orig_node->ogm_cnt_lock);
614 ret = batadv_orig_node_del_if(orig_node, max_if_num, 611 ret = batadv_orig_node_del_if(orig_node, max_if_num,
615 hard_iface->if_num); 612 hard_iface->if_num);