summaryrefslogtreecommitdiffstats
path: root/include/linux/hashtable.h
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 /include/linux/hashtable.h
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 'include/linux/hashtable.h')
-rw-r--r--include/linux/hashtable.h40
1 files changed, 19 insertions, 21 deletions
diff --git a/include/linux/hashtable.h b/include/linux/hashtable.h
index 227c62424f3c..a9df51f5d54c 100644
--- a/include/linux/hashtable.h
+++ b/include/linux/hashtable.h
@@ -115,51 +115,50 @@ static inline void hash_del_rcu(struct hlist_node *node)
115 * hash_for_each - iterate over a hashtable 115 * hash_for_each - iterate over a hashtable
116 * @name: hashtable to iterate 116 * @name: hashtable to iterate
117 * @bkt: integer to use as bucket loop cursor 117 * @bkt: integer to use as bucket loop cursor
118 * @node: the &struct list_head to use as a loop cursor for each entry
119 * @obj: the type * to use as a loop cursor for each entry 118 * @obj: the type * to use as a loop cursor for each entry
120 * @member: the name of the hlist_node within the struct 119 * @member: the name of the hlist_node within the struct
121 */ 120 */
122#define hash_for_each(name, bkt, node, obj, member) \ 121#define hash_for_each(name, bkt, obj, member) \
123 for ((bkt) = 0, node = NULL; node == NULL && (bkt) < HASH_SIZE(name); (bkt)++)\ 122 for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
124 hlist_for_each_entry(obj, node, &name[bkt], member) 123 (bkt)++)\
124 hlist_for_each_entry(obj, &name[bkt], member)
125 125
126/** 126/**
127 * hash_for_each_rcu - iterate over a rcu enabled hashtable 127 * hash_for_each_rcu - iterate over a rcu enabled hashtable
128 * @name: hashtable to iterate 128 * @name: hashtable to iterate
129 * @bkt: integer to use as bucket loop cursor 129 * @bkt: integer to use as bucket loop cursor
130 * @node: the &struct list_head to use as a loop cursor for each entry
131 * @obj: the type * to use as a loop cursor for each entry 130 * @obj: the type * to use as a loop cursor for each entry
132 * @member: the name of the hlist_node within the struct 131 * @member: the name of the hlist_node within the struct
133 */ 132 */
134#define hash_for_each_rcu(name, bkt, node, obj, member) \ 133#define hash_for_each_rcu(name, bkt, obj, member) \
135 for ((bkt) = 0, node = NULL; node == NULL && (bkt) < HASH_SIZE(name); (bkt)++)\ 134 for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
136 hlist_for_each_entry_rcu(obj, node, &name[bkt], member) 135 (bkt)++)\
136 hlist_for_each_entry_rcu(obj, &name[bkt], member)
137 137
138/** 138/**
139 * hash_for_each_safe - iterate over a hashtable safe against removal of 139 * hash_for_each_safe - iterate over a hashtable safe against removal of
140 * hash entry 140 * hash entry
141 * @name: hashtable to iterate 141 * @name: hashtable to iterate
142 * @bkt: integer to use as bucket loop cursor 142 * @bkt: integer to use as bucket loop cursor
143 * @node: the &struct list_head to use as a loop cursor for each entry
144 * @tmp: a &struct used for temporary storage 143 * @tmp: a &struct used for temporary storage
145 * @obj: the type * to use as a loop cursor for each entry 144 * @obj: the type * to use as a loop cursor for each entry
146 * @member: the name of the hlist_node within the struct 145 * @member: the name of the hlist_node within the struct
147 */ 146 */
148#define hash_for_each_safe(name, bkt, node, tmp, obj, member) \ 147#define hash_for_each_safe(name, bkt, tmp, obj, member) \
149 for ((bkt) = 0, node = NULL; node == NULL && (bkt) < HASH_SIZE(name); (bkt)++)\ 148 for ((bkt) = 0, obj = NULL; obj == NULL && (bkt) < HASH_SIZE(name);\
150 hlist_for_each_entry_safe(obj, node, tmp, &name[bkt], member) 149 (bkt)++)\
150 hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)
151 151
152/** 152/**
153 * hash_for_each_possible - iterate over all possible objects hashing to the 153 * hash_for_each_possible - iterate over all possible objects hashing to the
154 * same bucket 154 * same bucket
155 * @name: hashtable to iterate 155 * @name: hashtable to iterate
156 * @obj: the type * to use as a loop cursor for each entry 156 * @obj: the type * to use as a loop cursor for each entry
157 * @node: the &struct list_head to use as a loop cursor for each entry
158 * @member: the name of the hlist_node within the struct 157 * @member: the name of the hlist_node within the struct
159 * @key: the key of the objects to iterate over 158 * @key: the key of the objects to iterate over
160 */ 159 */
161#define hash_for_each_possible(name, obj, node, member, key) \ 160#define hash_for_each_possible(name, obj, member, key) \
162 hlist_for_each_entry(obj, node, &name[hash_min(key, HASH_BITS(name))], member) 161 hlist_for_each_entry(obj, &name[hash_min(key, HASH_BITS(name))], member)
163 162
164/** 163/**
165 * hash_for_each_possible_rcu - iterate over all possible objects hashing to the 164 * hash_for_each_possible_rcu - iterate over all possible objects hashing to the
@@ -167,25 +166,24 @@ static inline void hash_del_rcu(struct hlist_node *node)
167 * in a rcu enabled hashtable 166 * in a rcu enabled hashtable
168 * @name: hashtable to iterate 167 * @name: hashtable to iterate
169 * @obj: the type * to use as a loop cursor for each entry 168 * @obj: the type * to use as a loop cursor for each entry
170 * @node: the &struct list_head to use as a loop cursor for each entry
171 * @member: the name of the hlist_node within the struct 169 * @member: the name of the hlist_node within the struct
172 * @key: the key of the objects to iterate over 170 * @key: the key of the objects to iterate over
173 */ 171 */
174#define hash_for_each_possible_rcu(name, obj, node, member, key) \ 172#define hash_for_each_possible_rcu(name, obj, member, key) \
175 hlist_for_each_entry_rcu(obj, node, &name[hash_min(key, HASH_BITS(name))], member) 173 hlist_for_each_entry_rcu(obj, &name[hash_min(key, HASH_BITS(name))],\
174 member)
176 175
177/** 176/**
178 * hash_for_each_possible_safe - iterate over all possible objects hashing to the 177 * hash_for_each_possible_safe - iterate over all possible objects hashing to the
179 * same bucket safe against removals 178 * same bucket safe against removals
180 * @name: hashtable to iterate 179 * @name: hashtable to iterate
181 * @obj: the type * to use as a loop cursor for each entry 180 * @obj: the type * to use as a loop cursor for each entry
182 * @node: the &struct list_head to use as a loop cursor for each entry
183 * @tmp: a &struct used for temporary storage 181 * @tmp: a &struct used for temporary storage
184 * @member: the name of the hlist_node within the struct 182 * @member: the name of the hlist_node within the struct
185 * @key: the key of the objects to iterate over 183 * @key: the key of the objects to iterate over
186 */ 184 */
187#define hash_for_each_possible_safe(name, obj, node, tmp, member, key) \ 185#define hash_for_each_possible_safe(name, obj, tmp, member, key) \
188 hlist_for_each_entry_safe(obj, node, tmp, \ 186 hlist_for_each_entry_safe(obj, tmp,\
189 &name[hash_min(key, HASH_BITS(name))], member) 187 &name[hash_min(key, HASH_BITS(name))], member)
190 188
191 189