From bd6692ea74658bc084ba8fa1979549beda104be7 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Wed, 25 Oct 2017 16:54:09 +0200 Subject: peer: get rid of peer_for_each magic Since the peer list is protected by the device_update_lock, and since items are removed from the peer list before putting their final reference, we don't actually need to take a reference when iterating. This allows us to simplify the macro considerably. Suggested-by: Johannes Berg Signed-off-by: Jason A. Donenfeld --- src/peer.h | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'src/peer.h') diff --git a/src/peer.h b/src/peer.h index 3581c73..994c8b6 100644 --- a/src/peer.h +++ b/src/peer.h @@ -69,34 +69,4 @@ struct wireguard_peer *peer_lookup_by_index(struct wireguard_device *wg, u32 ind unsigned int peer_total_count(struct wireguard_device *wg); -/* This is a macro iterator of essentially as follows, with the - * exception that typing `break` in the ITERATOR_BODY will still - * actually put the peer reference: - * - * if (__should_lock) - * mutex_lock(&(__wg)->device_update_lock); - * else - * lockdep_assert_held(&(__wg)->device_update_lock) - * list_for_each_entry_safe (__peer, __temp, &(__wg)->peer_list, peer_list) { - * __peer = peer_rcu_get(__peer); - * if (!__peer) - * continue; - * ITERATOR_BODY - * peer_put(__peer); - * } - * if (__should_lock) - * mutex_unlock(&(__wg)->device_update_lock); - * - * While it's really ugly to look at, the code gcc produces from it is actually perfect. - */ -#define pfe_label(n) __PASTE(__PASTE(pfe_label_, n ## _), __LINE__) -#define peer_for_each(__wg, __peer, __temp, __should_lock) \ - if (1) { if (__should_lock) mutex_lock(&(__wg)->device_update_lock); else lockdep_assert_held(&(__wg)->device_update_lock); goto pfe_label(1); } else pfe_label(1): \ - if (1) goto pfe_label(2); else while (1) if (1) { if (__should_lock) mutex_unlock(&(__wg)->device_update_lock); break; } else pfe_label(2): \ - list_for_each_entry_safe (__peer, __temp, &(__wg)->peer_list, peer_list) \ - if (0) pfe_label(3): break; else \ - if (0); else for (__peer = peer_rcu_get(peer); __peer;) if (1) { goto pfe_label(4); pfe_label(5): break; } else while (1) if (1) goto pfe_label(5); else pfe_label(4): \ - if (1) { goto pfe_label(6); pfe_label(7):; } else while (1) if (1) goto pfe_label(3); else while (1) if (1) goto pfe_label(7); else pfe_label(6): \ - if (1) { goto pfe_label(8); pfe_label(9): peer_put(__peer); break; pfe_label(10): peer_put(__peer); } else while (1) if (1) goto pfe_label(9); else while (1) if (1) goto pfe_label(10); else pfe_label(8): - #endif /* _WG_PEER_H */ -- cgit v1.2.3