aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/hashtable.h40
-rw-r--r--include/linux/if_team.h6
-rw-r--r--include/linux/list.h49
-rw-r--r--include/linux/pid.h3
-rw-r--r--include/linux/rculist.h56
5 files changed, 72 insertions, 82 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
diff --git a/include/linux/if_team.h b/include/linux/if_team.h
index 4648d8021244..cfd21e3d5506 100644
--- a/include/linux/if_team.h
+++ b/include/linux/if_team.h
@@ -216,11 +216,10 @@ static inline struct hlist_head *team_port_index_hash(struct team *team,
216static inline struct team_port *team_get_port_by_index(struct team *team, 216static inline struct team_port *team_get_port_by_index(struct team *team,
217 int port_index) 217 int port_index)
218{ 218{
219 struct hlist_node *p;
220 struct team_port *port; 219 struct team_port *port;
221 struct hlist_head *head = team_port_index_hash(team, port_index); 220 struct hlist_head *head = team_port_index_hash(team, port_index);
222 221
223 hlist_for_each_entry(port, p, head, hlist) 222 hlist_for_each_entry(port, head, hlist)
224 if (port->index == port_index) 223 if (port->index == port_index)
225 return port; 224 return port;
226 return NULL; 225 return NULL;
@@ -228,11 +227,10 @@ static inline struct team_port *team_get_port_by_index(struct team *team,
228static inline struct team_port *team_get_port_by_index_rcu(struct team *team, 227static inline struct team_port *team_get_port_by_index_rcu(struct team *team,
229 int port_index) 228 int port_index)
230{ 229{
231 struct hlist_node *p;
232 struct team_port *port; 230 struct team_port *port;
233 struct hlist_head *head = team_port_index_hash(team, port_index); 231 struct hlist_head *head = team_port_index_hash(team, port_index);
234 232
235 hlist_for_each_entry_rcu(port, p, head, hlist) 233 hlist_for_each_entry_rcu(port, head, hlist)
236 if (port->index == port_index) 234 if (port->index == port_index)
237 return port; 235 return port;
238 return NULL; 236 return NULL;
diff --git a/include/linux/list.h b/include/linux/list.h
index cc6d2aa6b415..d991cc147c98 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -666,54 +666,49 @@ static inline void hlist_move_list(struct hlist_head *old,
666 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ 666 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
667 pos = n) 667 pos = n)
668 668
669#define hlist_entry_safe(ptr, type, member) \
670 (ptr) ? hlist_entry(ptr, type, member) : NULL
671
669/** 672/**
670 * hlist_for_each_entry - iterate over list of given type 673 * hlist_for_each_entry - iterate over list of given type
671 * @tpos: the type * to use as a loop cursor. 674 * @pos: the type * to use as a loop cursor.
672 * @pos: the &struct hlist_node to use as a loop cursor.
673 * @head: the head for your list. 675 * @head: the head for your list.
674 * @member: the name of the hlist_node within the struct. 676 * @member: the name of the hlist_node within the struct.
675 */ 677 */
676#define hlist_for_each_entry(tpos, pos, head, member) \ 678#define hlist_for_each_entry(pos, head, member) \
677 for (pos = (head)->first; \ 679 for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
678 pos && \ 680 pos; \
679 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 681 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
680 pos = pos->next)
681 682
682/** 683/**
683 * hlist_for_each_entry_continue - iterate over a hlist continuing after current point 684 * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
684 * @tpos: the type * to use as a loop cursor. 685 * @pos: the type * to use as a loop cursor.
685 * @pos: the &struct hlist_node to use as a loop cursor.
686 * @member: the name of the hlist_node within the struct. 686 * @member: the name of the hlist_node within the struct.
687 */ 687 */
688#define hlist_for_each_entry_continue(tpos, pos, member) \ 688#define hlist_for_each_entry_continue(pos, member) \
689 for (pos = (pos)->next; \ 689 for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
690 pos && \ 690 pos; \
691 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 691 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
692 pos = pos->next)
693 692
694/** 693/**
695 * hlist_for_each_entry_from - iterate over a hlist continuing from current point 694 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
696 * @tpos: the type * to use as a loop cursor. 695 * @pos: the type * to use as a loop cursor.
697 * @pos: the &struct hlist_node to use as a loop cursor.
698 * @member: the name of the hlist_node within the struct. 696 * @member: the name of the hlist_node within the struct.
699 */ 697 */
700#define hlist_for_each_entry_from(tpos, pos, member) \ 698#define hlist_for_each_entry_from(pos, member) \
701 for (; pos && \ 699 for (; pos; \
702 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 700 pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
703 pos = pos->next)
704 701
705/** 702/**
706 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry 703 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
707 * @tpos: the type * to use as a loop cursor. 704 * @pos: the type * to use as a loop cursor.
708 * @pos: the &struct hlist_node to use as a loop cursor.
709 * @n: another &struct hlist_node to use as temporary storage 705 * @n: another &struct hlist_node to use as temporary storage
710 * @head: the head for your list. 706 * @head: the head for your list.
711 * @member: the name of the hlist_node within the struct. 707 * @member: the name of the hlist_node within the struct.
712 */ 708 */
713#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ 709#define hlist_for_each_entry_safe(pos, n, head, member) \
714 for (pos = (head)->first; \ 710 for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
715 pos && ({ n = pos->next; 1; }) && \ 711 pos && ({ n = pos->member.next; 1; }); \
716 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 712 pos = hlist_entry_safe(n, typeof(*pos), member))
717 pos = n)
718 713
719#endif 714#endif
diff --git a/include/linux/pid.h b/include/linux/pid.h
index 2381c973d897..a089a3c447fc 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -176,9 +176,8 @@ pid_t pid_vnr(struct pid *pid);
176 176
177#define do_each_pid_task(pid, type, task) \ 177#define do_each_pid_task(pid, type, task) \
178 do { \ 178 do { \
179 struct hlist_node *pos___; \
180 if ((pid) != NULL) \ 179 if ((pid) != NULL) \
181 hlist_for_each_entry_rcu((task), pos___, \ 180 hlist_for_each_entry_rcu((task), \
182 &(pid)->tasks[type], pids[type].node) { 181 &(pid)->tasks[type], pids[type].node) {
183 182
184 /* 183 /*
diff --git a/include/linux/rculist.h b/include/linux/rculist.h
index c92dd28eaa6c..8089e35d47ac 100644
--- a/include/linux/rculist.h
+++ b/include/linux/rculist.h
@@ -445,8 +445,7 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
445 445
446/** 446/**
447 * hlist_for_each_entry_rcu - iterate over rcu list of given type 447 * hlist_for_each_entry_rcu - iterate over rcu list of given type
448 * @tpos: the type * to use as a loop cursor. 448 * @pos: the type * to use as a loop cursor.
449 * @pos: the &struct hlist_node to use as a loop cursor.
450 * @head: the head for your list. 449 * @head: the head for your list.
451 * @member: the name of the hlist_node within the struct. 450 * @member: the name of the hlist_node within the struct.
452 * 451 *
@@ -454,16 +453,16 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
454 * the _rcu list-mutation primitives such as hlist_add_head_rcu() 453 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
455 * as long as the traversal is guarded by rcu_read_lock(). 454 * as long as the traversal is guarded by rcu_read_lock().
456 */ 455 */
457#define hlist_for_each_entry_rcu(tpos, pos, head, member) \ 456#define hlist_for_each_entry_rcu(pos, head, member) \
458 for (pos = rcu_dereference_raw(hlist_first_rcu(head)); \ 457 for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\
459 pos && \ 458 typeof(*(pos)), member); \
460 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ 459 pos; \
461 pos = rcu_dereference_raw(hlist_next_rcu(pos))) 460 pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu(\
461 &(pos)->member)), typeof(*(pos)), member))
462 462
463/** 463/**
464 * hlist_for_each_entry_rcu_bh - iterate over rcu list of given type 464 * hlist_for_each_entry_rcu_bh - iterate over rcu list of given type
465 * @tpos: the type * to use as a loop cursor. 465 * @pos: the type * to use as a loop cursor.
466 * @pos: the &struct hlist_node to use as a loop cursor.
467 * @head: the head for your list. 466 * @head: the head for your list.
468 * @member: the name of the hlist_node within the struct. 467 * @member: the name of the hlist_node within the struct.
469 * 468 *
@@ -471,35 +470,36 @@ static inline void hlist_add_after_rcu(struct hlist_node *prev,
471 * the _rcu list-mutation primitives such as hlist_add_head_rcu() 470 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
472 * as long as the traversal is guarded by rcu_read_lock(). 471 * as long as the traversal is guarded by rcu_read_lock().
473 */ 472 */
474#define hlist_for_each_entry_rcu_bh(tpos, pos, head, member) \ 473#define hlist_for_each_entry_rcu_bh(pos, head, member) \
475 for (pos = rcu_dereference_bh((head)->first); \ 474 for (pos = hlist_entry_safe(rcu_dereference_bh(hlist_first_rcu(head)),\
476 pos && \ 475 typeof(*(pos)), member); \
477 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ 476 pos; \
478 pos = rcu_dereference_bh(pos->next)) 477 pos = hlist_entry_safe(rcu_dereference_bh(hlist_next_rcu(\
478 &(pos)->member)), typeof(*(pos)), member))
479 479
480/** 480/**
481 * hlist_for_each_entry_continue_rcu - iterate over a hlist continuing after current point 481 * hlist_for_each_entry_continue_rcu - iterate over a hlist continuing after current point
482 * @tpos: the type * to use as a loop cursor. 482 * @pos: the type * to use as a loop cursor.
483 * @pos: the &struct hlist_node to use as a loop cursor.
484 * @member: the name of the hlist_node within the struct. 483 * @member: the name of the hlist_node within the struct.
485 */ 484 */
486#define hlist_for_each_entry_continue_rcu(tpos, pos, member) \ 485#define hlist_for_each_entry_continue_rcu(pos, member) \
487 for (pos = rcu_dereference((pos)->next); \ 486 for (pos = hlist_entry_safe(rcu_dereference((pos)->member.next),\
488 pos && \ 487 typeof(*(pos)), member); \
489 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ 488 pos; \
490 pos = rcu_dereference(pos->next)) 489 pos = hlist_entry_safe(rcu_dereference((pos)->member.next),\
490 typeof(*(pos)), member))
491 491
492/** 492/**
493 * hlist_for_each_entry_continue_rcu_bh - iterate over a hlist continuing after current point 493 * hlist_for_each_entry_continue_rcu_bh - iterate over a hlist continuing after current point
494 * @tpos: the type * to use as a loop cursor. 494 * @pos: the type * to use as a loop cursor.
495 * @pos: the &struct hlist_node to use as a loop cursor.
496 * @member: the name of the hlist_node within the struct. 495 * @member: the name of the hlist_node within the struct.
497 */ 496 */
498#define hlist_for_each_entry_continue_rcu_bh(tpos, pos, member) \ 497#define hlist_for_each_entry_continue_rcu_bh(pos, member) \
499 for (pos = rcu_dereference_bh((pos)->next); \ 498 for (pos = hlist_entry_safe(rcu_dereference_bh((pos)->member.next),\
500 pos && \ 499 typeof(*(pos)), member); \
501 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; }); \ 500 pos; \
502 pos = rcu_dereference_bh(pos->next)) 501 pos = hlist_entry_safe(rcu_dereference_bh((pos)->member.next),\
502 typeof(*(pos)), member))
503 503
504 504
505#endif /* __KERNEL__ */ 505#endif /* __KERNEL__ */