4 #include <linux/types.h>
5 #include <linux/stddef.h>
6 #include <linux/poison.h>
7 #include <linux/const.h>
19 #define LIST_HEAD_INIT(name) { &(name), &(name) }
21 #define LIST_HEAD(name) \
22 struct list_head name = LIST_HEAD_INIT(name)
36 #ifndef CONFIG_DEBUG_LIST
98 #ifndef CONFIG_DEBUG_LIST
101 __list_del(entry->
prev, entry->
next);
106 __list_del(entry->
prev, entry->
next);
122 static inline void list_replace(
struct list_head *old,
125 new->next = old->
next;
126 new->next->prev =
new;
127 new->prev = old->
prev;
128 new->prev->next =
new;
131 static inline void list_replace_init(
struct list_head *old,
134 list_replace(old,
new);
145 INIT_LIST_HEAD(entry);
156 list_add(list, head);
204 static inline int list_empty_careful(
const struct list_head *
head)
207 return (next == head) && (next == head->
prev);
214 static inline void list_rotate_left(
struct list_head *head)
218 if (!list_empty(head)) {
220 list_move_tail(first, head);
228 static inline int list_is_singular(
const struct list_head *head)
230 return !list_empty(head) && (head->
next == head->
prev);
233 static inline void __list_cut_position(
struct list_head *
list,
241 head->
next = new_first;
262 if (list_empty(head))
264 if (list_is_singular(head) &&
265 (head->
next != entry && head != entry))
268 INIT_LIST_HEAD(list);
270 __list_cut_position(list, head, entry);
273 static inline void __list_splice(
const struct list_head *list,
292 static inline void list_splice(
const struct list_head *list,
295 if (!list_empty(list))
296 __list_splice(list, head, head->
next);
304 static inline void list_splice_tail(
struct list_head *list,
307 if (!list_empty(list))
308 __list_splice(list, head->
prev, head);
318 static inline void list_splice_init(
struct list_head *list,
321 if (!list_empty(list)) {
322 __list_splice(list, head, head->
next);
323 INIT_LIST_HEAD(list);
335 static inline void list_splice_tail_init(
struct list_head *list,
338 if (!list_empty(list)) {
339 __list_splice(list, head->
prev, head);
340 INIT_LIST_HEAD(list);
350 #define list_entry(ptr, type, member) \
351 container_of(ptr, type, member)
361 #define list_first_entry(ptr, type, member) \
362 list_entry((ptr)->next, type, member)
369 #define list_for_each(pos, head) \
370 for (pos = (head)->next; pos != (head); pos = pos->next)
380 #define __list_for_each(pos, head) \
381 for (pos = (head)->next; pos != (head); pos = pos->next)
388 #define list_for_each_prev(pos, head) \
389 for (pos = (head)->prev; pos != (head); pos = pos->prev)
397 #define list_for_each_safe(pos, n, head) \
398 for (pos = (head)->next, n = pos->next; pos != (head); \
399 pos = n, n = pos->next)
407 #define list_for_each_prev_safe(pos, n, head) \
408 for (pos = (head)->prev, n = pos->prev; \
410 pos = n, n = pos->prev)
418 #define list_for_each_entry(pos, head, member) \
419 for (pos = list_entry((head)->next, typeof(*pos), member); \
420 &pos->member != (head); \
421 pos = list_entry(pos->member.next, typeof(*pos), member))
429 #define list_for_each_entry_reverse(pos, head, member) \
430 for (pos = list_entry((head)->prev, typeof(*pos), member); \
431 &pos->member != (head); \
432 pos = list_entry(pos->member.prev, typeof(*pos), member))
442 #define list_prepare_entry(pos, head, member) \
443 ((pos) ? : list_entry(head, typeof(*pos), member))
454 #define list_for_each_entry_continue(pos, head, member) \
455 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
456 &pos->member != (head); \
457 pos = list_entry(pos->member.next, typeof(*pos), member))
468 #define list_for_each_entry_continue_reverse(pos, head, member) \
469 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
470 &pos->member != (head); \
471 pos = list_entry(pos->member.prev, typeof(*pos), member))
481 #define list_for_each_entry_from(pos, head, member) \
482 for (; &pos->member != (head); \
483 pos = list_entry(pos->member.next, typeof(*pos), member))
492 #define list_for_each_entry_safe(pos, n, head, member) \
493 for (pos = list_entry((head)->next, typeof(*pos), member), \
494 n = list_entry(pos->member.next, typeof(*pos), member); \
495 &pos->member != (head); \
496 pos = n, n = list_entry(n->member.next, typeof(*n), member))
508 #define list_for_each_entry_safe_continue(pos, n, head, member) \
509 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
510 n = list_entry(pos->member.next, typeof(*pos), member); \
511 &pos->member != (head); \
512 pos = n, n = list_entry(n->member.next, typeof(*n), member))
524 #define list_for_each_entry_safe_from(pos, n, head, member) \
525 for (n = list_entry(pos->member.next, typeof(*pos), member); \
526 &pos->member != (head); \
527 pos = n, n = list_entry(n->member.next, typeof(*n), member))
539 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
540 for (pos = list_entry((head)->prev, typeof(*pos), member), \
541 n = list_entry(pos->member.prev, typeof(*pos), member); \
542 &pos->member != (head); \
543 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
557 #define list_safe_reset_next(pos, n, member) \
558 n = list_entry(pos->member.next, typeof(*pos), member)
567 #define HLIST_HEAD_INIT { .first = NULL }
568 #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
569 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
570 static inline void INIT_HLIST_NODE(
struct hlist_node *
h)
576 static inline int hlist_unhashed(
const struct hlist_node *
h)
581 static inline int hlist_empty(
const struct hlist_head *
h)
586 static inline void __hlist_del(
struct hlist_node *
n)
595 static inline void hlist_del(
struct hlist_node *n)
602 static inline void hlist_del_init(
struct hlist_node *n)
604 if (!hlist_unhashed(n)) {
621 static inline void hlist_add_before(
struct hlist_node *n,
630 static inline void hlist_add_after(
struct hlist_node *n,
642 static inline void hlist_add_fake(
struct hlist_node *n)
651 static inline void hlist_move_list(
struct hlist_head *old,
654 new->first = old->
first;
656 new->first->pprev = &
new->first;
660 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
662 #define hlist_for_each(pos, head) \
663 for (pos = (head)->first; pos ; pos = pos->next)
665 #define hlist_for_each_safe(pos, n, head) \
666 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
676 #define hlist_for_each_entry(tpos, pos, head, member) \
677 for (pos = (head)->first; \
679 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
688 #define hlist_for_each_entry_continue(tpos, pos, member) \
689 for (pos = (pos)->next; \
691 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
700 #define hlist_for_each_entry_from(tpos, pos, member) \
702 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
713 #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
714 for (pos = (head)->first; \
715 pos && ({ n = pos->next; 1; }) && \
716 ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \