aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlink/af_netlink.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/netlink/af_netlink.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/netlink/af_netlink.c')
-rw-r--r--net/netlink/af_netlink.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index 8097b4f3ead4..1e3fd5bfcd86 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -248,11 +248,10 @@ static struct sock *netlink_lookup(struct net *net, int protocol, u32 portid)
248 struct nl_portid_hash *hash = &nl_table[protocol].hash; 248 struct nl_portid_hash *hash = &nl_table[protocol].hash;
249 struct hlist_head *head; 249 struct hlist_head *head;
250 struct sock *sk; 250 struct sock *sk;
251 struct hlist_node *node;
252 251
253 read_lock(&nl_table_lock); 252 read_lock(&nl_table_lock);
254 head = nl_portid_hashfn(hash, portid); 253 head = nl_portid_hashfn(hash, portid);
255 sk_for_each(sk, node, head) { 254 sk_for_each(sk, head) {
256 if (net_eq(sock_net(sk), net) && (nlk_sk(sk)->portid == portid)) { 255 if (net_eq(sock_net(sk), net) && (nlk_sk(sk)->portid == portid)) {
257 sock_hold(sk); 256 sock_hold(sk);
258 goto found; 257 goto found;
@@ -312,9 +311,9 @@ static int nl_portid_hash_rehash(struct nl_portid_hash *hash, int grow)
312 311
313 for (i = 0; i <= omask; i++) { 312 for (i = 0; i <= omask; i++) {
314 struct sock *sk; 313 struct sock *sk;
315 struct hlist_node *node, *tmp; 314 struct hlist_node *tmp;
316 315
317 sk_for_each_safe(sk, node, tmp, &otable[i]) 316 sk_for_each_safe(sk, tmp, &otable[i])
318 __sk_add_node(sk, nl_portid_hashfn(hash, nlk_sk(sk)->portid)); 317 __sk_add_node(sk, nl_portid_hashfn(hash, nlk_sk(sk)->portid));
319 } 318 }
320 319
@@ -344,7 +343,6 @@ static void
344netlink_update_listeners(struct sock *sk) 343netlink_update_listeners(struct sock *sk)
345{ 344{
346 struct netlink_table *tbl = &nl_table[sk->sk_protocol]; 345 struct netlink_table *tbl = &nl_table[sk->sk_protocol];
347 struct hlist_node *node;
348 unsigned long mask; 346 unsigned long mask;
349 unsigned int i; 347 unsigned int i;
350 struct listeners *listeners; 348 struct listeners *listeners;
@@ -355,7 +353,7 @@ netlink_update_listeners(struct sock *sk)
355 353
356 for (i = 0; i < NLGRPLONGS(tbl->groups); i++) { 354 for (i = 0; i < NLGRPLONGS(tbl->groups); i++) {
357 mask = 0; 355 mask = 0;
358 sk_for_each_bound(sk, node, &tbl->mc_list) { 356 sk_for_each_bound(sk, &tbl->mc_list) {
359 if (i < NLGRPLONGS(nlk_sk(sk)->ngroups)) 357 if (i < NLGRPLONGS(nlk_sk(sk)->ngroups))
360 mask |= nlk_sk(sk)->groups[i]; 358 mask |= nlk_sk(sk)->groups[i];
361 } 359 }
@@ -371,18 +369,17 @@ static int netlink_insert(struct sock *sk, struct net *net, u32 portid)
371 struct hlist_head *head; 369 struct hlist_head *head;
372 int err = -EADDRINUSE; 370 int err = -EADDRINUSE;
373 struct sock *osk; 371 struct sock *osk;
374 struct hlist_node *node;
375 int len; 372 int len;
376 373
377 netlink_table_grab(); 374 netlink_table_grab();
378 head = nl_portid_hashfn(hash, portid); 375 head = nl_portid_hashfn(hash, portid);
379 len = 0; 376 len = 0;
380 sk_for_each(osk, node, head) { 377 sk_for_each(osk, head) {
381 if (net_eq(sock_net(osk), net) && (nlk_sk(osk)->portid == portid)) 378 if (net_eq(sock_net(osk), net) && (nlk_sk(osk)->portid == portid))
382 break; 379 break;
383 len++; 380 len++;
384 } 381 }
385 if (node) 382 if (osk)
386 goto err; 383 goto err;
387 384
388 err = -EBUSY; 385 err = -EBUSY;
@@ -575,7 +572,6 @@ static int netlink_autobind(struct socket *sock)
575 struct nl_portid_hash *hash = &nl_table[sk->sk_protocol].hash; 572 struct nl_portid_hash *hash = &nl_table[sk->sk_protocol].hash;
576 struct hlist_head *head; 573 struct hlist_head *head;
577 struct sock *osk; 574 struct sock *osk;
578 struct hlist_node *node;
579 s32 portid = task_tgid_vnr(current); 575 s32 portid = task_tgid_vnr(current);
580 int err; 576 int err;
581 static s32 rover = -4097; 577 static s32 rover = -4097;
@@ -584,7 +580,7 @@ retry:
584 cond_resched(); 580 cond_resched();
585 netlink_table_grab(); 581 netlink_table_grab();
586 head = nl_portid_hashfn(hash, portid); 582 head = nl_portid_hashfn(hash, portid);
587 sk_for_each(osk, node, head) { 583 sk_for_each(osk, head) {
588 if (!net_eq(sock_net(osk), net)) 584 if (!net_eq(sock_net(osk), net))
589 continue; 585 continue;
590 if (nlk_sk(osk)->portid == portid) { 586 if (nlk_sk(osk)->portid == portid) {
@@ -1101,7 +1097,6 @@ int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, u32 portid
1101{ 1097{
1102 struct net *net = sock_net(ssk); 1098 struct net *net = sock_net(ssk);
1103 struct netlink_broadcast_data info; 1099 struct netlink_broadcast_data info;
1104 struct hlist_node *node;
1105 struct sock *sk; 1100 struct sock *sk;
1106 1101
1107 skb = netlink_trim(skb, allocation); 1102 skb = netlink_trim(skb, allocation);
@@ -1124,7 +1119,7 @@ int netlink_broadcast_filtered(struct sock *ssk, struct sk_buff *skb, u32 portid
1124 1119
1125 netlink_lock_table(); 1120 netlink_lock_table();
1126 1121
1127 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) 1122 sk_for_each_bound(sk, &nl_table[ssk->sk_protocol].mc_list)
1128 do_one_broadcast(sk, &info); 1123 do_one_broadcast(sk, &info);
1129 1124
1130 consume_skb(skb); 1125 consume_skb(skb);
@@ -1200,7 +1195,6 @@ out:
1200int netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code) 1195int netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code)
1201{ 1196{
1202 struct netlink_set_err_data info; 1197 struct netlink_set_err_data info;
1203 struct hlist_node *node;
1204 struct sock *sk; 1198 struct sock *sk;
1205 int ret = 0; 1199 int ret = 0;
1206 1200
@@ -1212,7 +1206,7 @@ int netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code)
1212 1206
1213 read_lock(&nl_table_lock); 1207 read_lock(&nl_table_lock);
1214 1208
1215 sk_for_each_bound(sk, node, &nl_table[ssk->sk_protocol].mc_list) 1209 sk_for_each_bound(sk, &nl_table[ssk->sk_protocol].mc_list)
1216 ret += do_one_set_err(sk, &info); 1210 ret += do_one_set_err(sk, &info);
1217 1211
1218 read_unlock(&nl_table_lock); 1212 read_unlock(&nl_table_lock);
@@ -1676,10 +1670,9 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
1676void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group) 1670void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
1677{ 1671{
1678 struct sock *sk; 1672 struct sock *sk;
1679 struct hlist_node *node;
1680 struct netlink_table *tbl = &nl_table[ksk->sk_protocol]; 1673 struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
1681 1674
1682 sk_for_each_bound(sk, node, &tbl->mc_list) 1675 sk_for_each_bound(sk, &tbl->mc_list)
1683 netlink_update_socket_mc(nlk_sk(sk), group, 0); 1676 netlink_update_socket_mc(nlk_sk(sk), group, 0);
1684} 1677}
1685 1678
@@ -1974,14 +1967,13 @@ static struct sock *netlink_seq_socket_idx(struct seq_file *seq, loff_t pos)
1974 struct nl_seq_iter *iter = seq->private; 1967 struct nl_seq_iter *iter = seq->private;
1975 int i, j; 1968 int i, j;
1976 struct sock *s; 1969 struct sock *s;
1977 struct hlist_node *node;
1978 loff_t off = 0; 1970 loff_t off = 0;
1979 1971
1980 for (i = 0; i < MAX_LINKS; i++) { 1972 for (i = 0; i < MAX_LINKS; i++) {
1981 struct nl_portid_hash *hash = &nl_table[i].hash; 1973 struct nl_portid_hash *hash = &nl_table[i].hash;
1982 1974
1983 for (j = 0; j <= hash->mask; j++) { 1975 for (j = 0; j <= hash->mask; j++) {
1984 sk_for_each(s, node, &hash->table[j]) { 1976 sk_for_each(s, &hash->table[j]) {
1985 if (sock_net(s) != seq_file_net(seq)) 1977 if (sock_net(s) != seq_file_net(seq))
1986 continue; 1978 continue;
1987 if (off == pos) { 1979 if (off == pos) {