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