1 #ifndef _LINUX_LIST_H
2 #define _LINUX_LIST_H
3
4 #if 0
5 #include <linux/types.h>
6 #include <linux/stddef.h>
7 #include <linux/poison.h>
8 #include <linux/const.h>
9 #else
10
11 #undef offsetof
12 #ifdef __compiler_offsetof
13 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
14 #else
15 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
16 #endif
17
18 /**
19 * container_of - cast a member of a structure out to the containing structure
20 * @ptr: the pointer to the member.
21 * @type: the type of the container struct this is embedded in.
22 * @member: the name of the member within the struct.
23 *
24 */
25 #define container_of(ptr, type, member) ({ \
26 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
27 (type *)( (char *)__mptr - offsetof(type,member) );})
28
29 struct list_head {
30 struct list_head *next, *prev;
31 };
32
33 struct hlist_head {
34 struct hlist_node *first;
35 };
36
37 struct hlist_node {
38 struct hlist_node *next, **pprev;
39 };
40
41 /*
42 * Architectures might want to move the poison pointer offset
43 * into some well-recognized area such as 0xdead000000000000,
44 * that is also not mappable by user-space exploits:
45 */
46 #ifdef CONFIG_ILLEGAL_POINTER_VALUE
47 # define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
48 #else
49 # define POISON_POINTER_DELTA 0
50 #endif
51
52 /*
53 * These are non-NULL pointers that will result in page faults
54 * under normal circumstances, used to verify that nobody uses
55 * non-initialized list entries.
56 */
57 #define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
58 #define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
59
60 #endif /* 0 */
61
62 /*
63 * Simple doubly linked list implementation.
64 *
65 * Some of the internal functions ("__xxx") are useful when
66 * manipulating whole lists rather than single entries, as
67 * sometimes we already know the next/prev entries and we can
68 * generate better code by using them directly rather than
69 * using the generic single-entry routines.
70 */
71
72 #define LIST_HEAD_INIT(name) { &(name), &(name) }
73
74 #define LIST_HEAD(name) \
75 struct list_head name = LIST_HEAD_INIT(name)
76
INIT_LIST_HEAD(struct list_head * list)77 static inline void INIT_LIST_HEAD(struct list_head *list)
78 {
79 list->next = list;
80 list->prev = list;
81 }
82
83 /*
84 * Insert a new entry between two known consecutive entries.
85 *
86 * This is only for internal list manipulation where we know
87 * the prev/next entries already!
88 */
89 #ifndef CONFIG_DEBUG_LIST
__list_add(struct list_head * new,struct list_head * prev,struct list_head * next)90 static inline void __list_add(struct list_head *new,
91 struct list_head *prev,
92 struct list_head *next)
93 {
94 next->prev = new;
95 new->next = next;
96 new->prev = prev;
97 prev->next = new;
98 }
99 #else
100 extern void __list_add(struct list_head *new,
101 struct list_head *prev,
102 struct list_head *next);
103 #endif
104
105 /**
106 * list_add - add a new entry
107 * @new: new entry to be added
108 * @head: list head to add it after
109 *
110 * Insert a new entry after the specified head.
111 * This is good for implementing stacks.
112 */
list_add(struct list_head * new,struct list_head * head)113 static inline void list_add(struct list_head *new, struct list_head *head)
114 {
115 __list_add(new, head, head->next);
116 }
117
118
119 /**
120 * list_add_tail - add a new entry
121 * @new: new entry to be added
122 * @head: list head to add it before
123 *
124 * Insert a new entry before the specified head.
125 * This is useful for implementing queues.
126 */
list_add_tail(struct list_head * new,struct list_head * head)127 static inline void list_add_tail(struct list_head *new, struct list_head *head)
128 {
129 __list_add(new, head->prev, head);
130 }
131
132 /*
133 * Delete a list entry by making the prev/next entries
134 * point to each other.
135 *
136 * This is only for internal list manipulation where we know
137 * the prev/next entries already!
138 */
__list_del(struct list_head * prev,struct list_head * next)139 static inline void __list_del(struct list_head * prev, struct list_head * next)
140 {
141 next->prev = prev;
142 prev->next = next;
143 }
144
145 /**
146 * list_del - deletes entry from list.
147 * @entry: the element to delete from the list.
148 * Note: list_empty() on entry does not return true after this, the entry is
149 * in an undefined state.
150 */
151 #ifndef CONFIG_DEBUG_LIST
__list_del_entry(struct list_head * entry)152 static inline void __list_del_entry(struct list_head *entry)
153 {
154 __list_del(entry->prev, entry->next);
155 }
156
list_del(struct list_head * entry)157 static inline void list_del(struct list_head *entry)
158 {
159 __list_del(entry->prev, entry->next);
160 entry->next = LIST_POISON1;
161 entry->prev = LIST_POISON2;
162 }
163 #else
164 extern void __list_del_entry(struct list_head *entry);
165 extern void list_del(struct list_head *entry);
166 #endif
167
168 /**
169 * list_replace - replace old entry by new one
170 * @old : the element to be replaced
171 * @new : the new element to insert
172 *
173 * If @old was empty, it will be overwritten.
174 */
list_replace(struct list_head * old,struct list_head * new)175 static inline void list_replace(struct list_head *old,
176 struct list_head *new)
177 {
178 new->next = old->next;
179 new->next->prev = new;
180 new->prev = old->prev;
181 new->prev->next = new;
182 }
183
list_replace_init(struct list_head * old,struct list_head * new)184 static inline void list_replace_init(struct list_head *old,
185 struct list_head *new)
186 {
187 list_replace(old, new);
188 INIT_LIST_HEAD(old);
189 }
190
191 /**
192 * list_del_init - deletes entry from list and reinitialize it.
193 * @entry: the element to delete from the list.
194 */
list_del_init(struct list_head * entry)195 static inline void list_del_init(struct list_head *entry)
196 {
197 __list_del_entry(entry);
198 INIT_LIST_HEAD(entry);
199 }
200
201 /**
202 * list_move - delete from one list and add as another's head
203 * @list: the entry to move
204 * @head: the head that will precede our entry
205 */
list_move(struct list_head * list,struct list_head * head)206 static inline void list_move(struct list_head *list, struct list_head *head)
207 {
208 __list_del_entry(list);
209 list_add(list, head);
210 }
211
212 /**
213 * list_move_tail - delete from one list and add as another's tail
214 * @list: the entry to move
215 * @head: the head that will follow our entry
216 */
list_move_tail(struct list_head * list,struct list_head * head)217 static inline void list_move_tail(struct list_head *list,
218 struct list_head *head)
219 {
220 __list_del_entry(list);
221 list_add_tail(list, head);
222 }
223
224 /**
225 * list_is_last - tests whether @list is the last entry in list @head
226 * @list: the entry to test
227 * @head: the head of the list
228 */
list_is_last(const struct list_head * list,const struct list_head * head)229 static inline int list_is_last(const struct list_head *list,
230 const struct list_head *head)
231 {
232 return list->next == head;
233 }
234
235 /**
236 * list_empty - tests whether a list is empty
237 * @head: the list to test.
238 */
list_empty(const struct list_head * head)239 static inline int list_empty(const struct list_head *head)
240 {
241 return head->next == head;
242 }
243
244 /**
245 * list_empty_careful - tests whether a list is empty and not being modified
246 * @head: the list to test
247 *
248 * Description:
249 * tests whether a list is empty _and_ checks that no other CPU might be
250 * in the process of modifying either member (next or prev)
251 *
252 * NOTE: using list_empty_careful() without synchronization
253 * can only be safe if the only activity that can happen
254 * to the list entry is list_del_init(). Eg. it cannot be used
255 * if another CPU could re-list_add() it.
256 */
list_empty_careful(const struct list_head * head)257 static inline int list_empty_careful(const struct list_head *head)
258 {
259 struct list_head *next = head->next;
260 return (next == head) && (next == head->prev);
261 }
262
263 /**
264 * list_rotate_left - rotate the list to the left
265 * @head: the head of the list
266 */
list_rotate_left(struct list_head * head)267 static inline void list_rotate_left(struct list_head *head)
268 {
269 struct list_head *first;
270
271 if (!list_empty(head)) {
272 first = head->next;
273 list_move_tail(first, head);
274 }
275 }
276
277 /**
278 * list_is_singular - tests whether a list has just one entry.
279 * @head: the list to test.
280 */
list_is_singular(const struct list_head * head)281 static inline int list_is_singular(const struct list_head *head)
282 {
283 return !list_empty(head) && (head->next == head->prev);
284 }
285
__list_cut_position(struct list_head * list,struct list_head * head,struct list_head * entry)286 static inline void __list_cut_position(struct list_head *list,
287 struct list_head *head, struct list_head *entry)
288 {
289 struct list_head *new_first = entry->next;
290 list->next = head->next;
291 list->next->prev = list;
292 list->prev = entry;
293 entry->next = list;
294 head->next = new_first;
295 new_first->prev = head;
296 }
297
298 /**
299 * list_cut_position - cut a list into two
300 * @list: a new list to add all removed entries
301 * @head: a list with entries
302 * @entry: an entry within head, could be the head itself
303 * and if so we won't cut the list
304 *
305 * This helper moves the initial part of @head, up to and
306 * including @entry, from @head to @list. You should
307 * pass on @entry an element you know is on @head. @list
308 * should be an empty list or a list you do not care about
309 * losing its data.
310 *
311 */
list_cut_position(struct list_head * list,struct list_head * head,struct list_head * entry)312 static inline void list_cut_position(struct list_head *list,
313 struct list_head *head, struct list_head *entry)
314 {
315 if (list_empty(head))
316 return;
317 if (list_is_singular(head) &&
318 (head->next != entry && head != entry))
319 return;
320 if (entry == head)
321 INIT_LIST_HEAD(list);
322 else
323 __list_cut_position(list, head, entry);
324 }
325
__list_splice(const struct list_head * list,struct list_head * prev,struct list_head * next)326 static inline void __list_splice(const struct list_head *list,
327 struct list_head *prev,
328 struct list_head *next)
329 {
330 struct list_head *first = list->next;
331 struct list_head *last = list->prev;
332
333 first->prev = prev;
334 prev->next = first;
335
336 last->next = next;
337 next->prev = last;
338 }
339
340 /**
341 * list_splice - join two lists, this is designed for stacks
342 * @list: the new list to add.
343 * @head: the place to add it in the first list.
344 */
list_splice(const struct list_head * list,struct list_head * head)345 static inline void list_splice(const struct list_head *list,
346 struct list_head *head)
347 {
348 if (!list_empty(list))
349 __list_splice(list, head, head->next);
350 }
351
352 /**
353 * list_splice_tail - join two lists, each list being a queue
354 * @list: the new list to add.
355 * @head: the place to add it in the first list.
356 */
list_splice_tail(struct list_head * list,struct list_head * head)357 static inline void list_splice_tail(struct list_head *list,
358 struct list_head *head)
359 {
360 if (!list_empty(list))
361 __list_splice(list, head->prev, head);
362 }
363
364 /**
365 * list_splice_init - join two lists and reinitialise the emptied list.
366 * @list: the new list to add.
367 * @head: the place to add it in the first list.
368 *
369 * The list at @list is reinitialised
370 */
list_splice_init(struct list_head * list,struct list_head * head)371 static inline void list_splice_init(struct list_head *list,
372 struct list_head *head)
373 {
374 if (!list_empty(list)) {
375 __list_splice(list, head, head->next);
376 INIT_LIST_HEAD(list);
377 }
378 }
379
380 /**
381 * list_splice_tail_init - join two lists and reinitialise the emptied list
382 * @list: the new list to add.
383 * @head: the place to add it in the first list.
384 *
385 * Each of the lists is a queue.
386 * The list at @list is reinitialised
387 */
list_splice_tail_init(struct list_head * list,struct list_head * head)388 static inline void list_splice_tail_init(struct list_head *list,
389 struct list_head *head)
390 {
391 if (!list_empty(list)) {
392 __list_splice(list, head->prev, head);
393 INIT_LIST_HEAD(list);
394 }
395 }
396
397 /**
398 * list_entry - get the struct for this entry
399 * @ptr: the &struct list_head pointer.
400 * @type: the type of the struct this is embedded in.
401 * @member: the name of the list_struct within the struct.
402 */
403 #define list_entry(ptr, type, member) \
404 container_of(ptr, type, member)
405
406 /**
407 * list_first_entry - get the first element from a list
408 * @ptr: the list head to take the element from.
409 * @type: the type of the struct this is embedded in.
410 * @member: the name of the list_struct within the struct.
411 *
412 * Note, that list is expected to be not empty.
413 */
414 #define list_first_entry(ptr, type, member) \
415 list_entry((ptr)->next, type, member)
416
417 /**
418 * list_for_each - iterate over a list
419 * @pos: the &struct list_head to use as a loop cursor.
420 * @head: the head for your list.
421 */
422 #define list_for_each(pos, head) \
423 for (pos = (head)->next; pos != (head); pos = pos->next)
424
425 /**
426 * __list_for_each - iterate over a list
427 * @pos: the &struct list_head to use as a loop cursor.
428 * @head: the head for your list.
429 *
430 * This variant doesn't differ from list_for_each() any more.
431 * We don't do prefetching in either case.
432 */
433 #define __list_for_each(pos, head) \
434 for (pos = (head)->next; pos != (head); pos = pos->next)
435
436 /**
437 * list_for_each_prev - iterate over a list backwards
438 * @pos: the &struct list_head to use as a loop cursor.
439 * @head: the head for your list.
440 */
441 #define list_for_each_prev(pos, head) \
442 for (pos = (head)->prev; pos != (head); pos = pos->prev)
443
444 /**
445 * list_for_each_safe - iterate over a list safe against removal of list entry
446 * @pos: the &struct list_head to use as a loop cursor.
447 * @n: another &struct list_head to use as temporary storage
448 * @head: the head for your list.
449 */
450 #define list_for_each_safe(pos, n, head) \
451 for (pos = (head)->next, n = pos->next; pos != (head); \
452 pos = n, n = pos->next)
453
454 /**
455 * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
456 * @pos: the &struct list_head to use as a loop cursor.
457 * @n: another &struct list_head to use as temporary storage
458 * @head: the head for your list.
459 */
460 #define list_for_each_prev_safe(pos, n, head) \
461 for (pos = (head)->prev, n = pos->prev; \
462 pos != (head); \
463 pos = n, n = pos->prev)
464
465 /**
466 * list_for_each_entry - iterate over list of given type
467 * @pos: the type * to use as a loop cursor.
468 * @head: the head for your list.
469 * @member: the name of the list_struct within the struct.
470 */
471 #define list_for_each_entry(pos, head, member) \
472 for (pos = list_entry((head)->next, typeof(*pos), member); \
473 &pos->member != (head); \
474 pos = list_entry(pos->member.next, typeof(*pos), member))
475
476 /**
477 * list_for_each_entry_reverse - iterate backwards over list of given type.
478 * @pos: the type * to use as a loop cursor.
479 * @head: the head for your list.
480 * @member: the name of the list_struct within the struct.
481 */
482 #define list_for_each_entry_reverse(pos, head, member) \
483 for (pos = list_entry((head)->prev, typeof(*pos), member); \
484 &pos->member != (head); \
485 pos = list_entry(pos->member.prev, typeof(*pos), member))
486
487 /**
488 * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
489 * @pos: the type * to use as a start point
490 * @head: the head of the list
491 * @member: the name of the list_struct within the struct.
492 *
493 * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
494 */
495 #define list_prepare_entry(pos, head, member) \
496 ((pos) ? : list_entry(head, typeof(*pos), member))
497
498 /**
499 * list_for_each_entry_continue - continue iteration over list of given type
500 * @pos: the type * to use as a loop cursor.
501 * @head: the head for your list.
502 * @member: the name of the list_struct within the struct.
503 *
504 * Continue to iterate over list of given type, continuing after
505 * the current position.
506 */
507 #define list_for_each_entry_continue(pos, head, member) \
508 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
509 &pos->member != (head); \
510 pos = list_entry(pos->member.next, typeof(*pos), member))
511
512 /**
513 * list_for_each_entry_continue_reverse - iterate backwards from the given point
514 * @pos: the type * to use as a loop cursor.
515 * @head: the head for your list.
516 * @member: the name of the list_struct within the struct.
517 *
518 * Start to iterate over list of given type backwards, continuing after
519 * the current position.
520 */
521 #define list_for_each_entry_continue_reverse(pos, head, member) \
522 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
523 &pos->member != (head); \
524 pos = list_entry(pos->member.prev, typeof(*pos), member))
525
526 /**
527 * list_for_each_entry_from - iterate over list of given type from the current point
528 * @pos: the type * to use as a loop cursor.
529 * @head: the head for your list.
530 * @member: the name of the list_struct within the struct.
531 *
532 * Iterate over list of given type, continuing from current position.
533 */
534 #define list_for_each_entry_from(pos, head, member) \
535 for (; &pos->member != (head); \
536 pos = list_entry(pos->member.next, typeof(*pos), member))
537
538 /**
539 * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
540 * @pos: the type * to use as a loop cursor.
541 * @n: another type * to use as temporary storage
542 * @head: the head for your list.
543 * @member: the name of the list_struct within the struct.
544 */
545 #define list_for_each_entry_safe(pos, n, head, member) \
546 for (pos = list_entry((head)->next, typeof(*pos), member), \
547 n = list_entry(pos->member.next, typeof(*pos), member); \
548 &pos->member != (head); \
549 pos = n, n = list_entry(n->member.next, typeof(*n), member))
550
551 /**
552 * list_for_each_entry_safe_continue - continue list iteration safe against removal
553 * @pos: the type * to use as a loop cursor.
554 * @n: another type * to use as temporary storage
555 * @head: the head for your list.
556 * @member: the name of the list_struct within the struct.
557 *
558 * Iterate over list of given type, continuing after current point,
559 * safe against removal of list entry.
560 */
561 #define list_for_each_entry_safe_continue(pos, n, head, member) \
562 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
563 n = list_entry(pos->member.next, typeof(*pos), member); \
564 &pos->member != (head); \
565 pos = n, n = list_entry(n->member.next, typeof(*n), member))
566
567 /**
568 * list_for_each_entry_safe_from - iterate over list from current point safe against removal
569 * @pos: the type * to use as a loop cursor.
570 * @n: another type * to use as temporary storage
571 * @head: the head for your list.
572 * @member: the name of the list_struct within the struct.
573 *
574 * Iterate over list of given type from current point, safe against
575 * removal of list entry.
576 */
577 #define list_for_each_entry_safe_from(pos, n, head, member) \
578 for (n = list_entry(pos->member.next, typeof(*pos), member); \
579 &pos->member != (head); \
580 pos = n, n = list_entry(n->member.next, typeof(*n), member))
581
582 /**
583 * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
584 * @pos: the type * to use as a loop cursor.
585 * @n: another type * to use as temporary storage
586 * @head: the head for your list.
587 * @member: the name of the list_struct within the struct.
588 *
589 * Iterate backwards over list of given type, safe against removal
590 * of list entry.
591 */
592 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
593 for (pos = list_entry((head)->prev, typeof(*pos), member), \
594 n = list_entry(pos->member.prev, typeof(*pos), member); \
595 &pos->member != (head); \
596 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
597
598 /**
599 * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
600 * @pos: the loop cursor used in the list_for_each_entry_safe loop
601 * @n: temporary storage used in list_for_each_entry_safe
602 * @member: the name of the list_struct within the struct.
603 *
604 * list_safe_reset_next is not safe to use in general if the list may be
605 * modified concurrently (eg. the lock is dropped in the loop body). An
606 * exception to this is if the cursor element (pos) is pinned in the list,
607 * and list_safe_reset_next is called after re-taking the lock and before
608 * completing the current iteration of the loop body.
609 */
610 #define list_safe_reset_next(pos, n, member) \
611 n = list_entry(pos->member.next, typeof(*pos), member)
612
613 /*
614 * Double linked lists with a single pointer list head.
615 * Mostly useful for hash tables where the two pointer list head is
616 * too wasteful.
617 * You lose the ability to access the tail in O(1).
618 */
619
620 #define HLIST_HEAD_INIT { .first = NULL }
621 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
622 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
INIT_HLIST_NODE(struct hlist_node * h)623 static inline void INIT_HLIST_NODE(struct hlist_node *h)
624 {
625 h->next = NULL;
626 h->pprev = NULL;
627 }
628
hlist_unhashed(const struct hlist_node * h)629 static inline int hlist_unhashed(const struct hlist_node *h)
630 {
631 return !h->pprev;
632 }
633
hlist_empty(const struct hlist_head * h)634 static inline int hlist_empty(const struct hlist_head *h)
635 {
636 return !h->first;
637 }
638
__hlist_del(struct hlist_node * n)639 static inline void __hlist_del(struct hlist_node *n)
640 {
641 struct hlist_node *next = n->next;
642 struct hlist_node **pprev = n->pprev;
643 *pprev = next;
644 if (next)
645 next->pprev = pprev;
646 }
647
hlist_del(struct hlist_node * n)648 static inline void hlist_del(struct hlist_node *n)
649 {
650 __hlist_del(n);
651 n->next = LIST_POISON1;
652 n->pprev = LIST_POISON2;
653 }
654
hlist_del_init(struct hlist_node * n)655 static inline void hlist_del_init(struct hlist_node *n)
656 {
657 if (!hlist_unhashed(n)) {
658 __hlist_del(n);
659 INIT_HLIST_NODE(n);
660 }
661 }
662
hlist_add_head(struct hlist_node * n,struct hlist_head * h)663 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
664 {
665 struct hlist_node *first = h->first;
666 n->next = first;
667 if (first)
668 first->pprev = &n->next;
669 h->first = n;
670 n->pprev = &h->first;
671 }
672
673 /* next must be != NULL */
hlist_add_before(struct hlist_node * n,struct hlist_node * next)674 static inline void hlist_add_before(struct hlist_node *n,
675 struct hlist_node *next)
676 {
677 n->pprev = next->pprev;
678 n->next = next;
679 next->pprev = &n->next;
680 *(n->pprev) = n;
681 }
682
hlist_add_after(struct hlist_node * n,struct hlist_node * next)683 static inline void hlist_add_after(struct hlist_node *n,
684 struct hlist_node *next)
685 {
686 next->next = n->next;
687 n->next = next;
688 next->pprev = &n->next;
689
690 if(next->next)
691 next->next->pprev = &next->next;
692 }
693
694 /* after that we'll appear to be on some hlist and hlist_del will work */
hlist_add_fake(struct hlist_node * n)695 static inline void hlist_add_fake(struct hlist_node *n)
696 {
697 n->pprev = &n->next;
698 }
699
700 /*
701 * Move a list from one list head to another. Fixup the pprev
702 * reference of the first entry if it exists.
703 */
hlist_move_list(struct hlist_head * old,struct hlist_head * new)704 static inline void hlist_move_list(struct hlist_head *old,
705 struct hlist_head *new)
706 {
707 new->first = old->first;
708 if (new->first)
709 new->first->pprev = &new->first;
710 old->first = NULL;
711 }
712
713 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
714
715 #define hlist_for_each(pos, head) \
716 for (pos = (head)->first; pos ; pos = pos->next)
717
718 #define hlist_for_each_safe(pos, n, head) \
719 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
720 pos = n)
721
722 /**
723 * hlist_for_each_entry - iterate over list of given type
724 * @tpos: the type * to use as a loop cursor.
725 * @pos: the &struct hlist_node to use as a loop cursor.
726 * @head: the head for your list.
727 * @member: the name of the hlist_node within the struct.
728 */
729 #define hlist_for_each_entry(tpos, pos, head, member) \
730 for (pos = (head)->first; \
731 pos && \
732 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
733 pos = pos->next)
734
735 /**
736 * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
737 * @tpos: the type * to use as a loop cursor.
738 * @pos: the &struct hlist_node to use as a loop cursor.
739 * @member: the name of the hlist_node within the struct.
740 */
741 #define hlist_for_each_entry_continue(tpos, pos, member) \
742 for (pos = (pos)->next; \
743 pos && \
744 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
745 pos = pos->next)
746
747 /**
748 * hlist_for_each_entry_from - iterate over a hlist continuing from current point
749 * @tpos: the type * to use as a loop cursor.
750 * @pos: the &struct hlist_node to use as a loop cursor.
751 * @member: the name of the hlist_node within the struct.
752 */
753 #define hlist_for_each_entry_from(tpos, pos, member) \
754 for (; pos && \
755 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
756 pos = pos->next)
757
758 /**
759 * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
760 * @tpos: the type * to use as a loop cursor.
761 * @pos: the &struct hlist_node to use as a loop cursor.
762 * @n: another &struct hlist_node to use as temporary storage
763 * @head: the head for your list.
764 * @member: the name of the hlist_node within the struct.
765 */
766 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
767 for (pos = (head)->first; \
768 pos && ({ n = pos->next; 1; }) && \
769 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
770 pos = n)
771
772 #endif
773