5 * These are non-NULL pointers that will result in page faults
6 * under normal circumstances, used to verify that nobody uses
7 * non-initialized list entries.
9 #define LIST_POISON1 ((void *) 0x00100100)
10 #define LIST_POISON2 ((void *) 0x00200200)
13 struct list_head *next, *prev;
16 #define LIST_HEAD_INIT(name) { &(name), &(name) }
18 #define LIST_HEAD(name) \
19 struct list_head name = LIST_HEAD_INIT(name)
21 static inline void INIT_LIST_HEAD(struct list_head *list)
28 * Insert a new entry between two known consecutive entries.
30 * This is only for internal list manipulation where we know
31 * the prev/next entries already!
33 static inline void __list_add(struct list_head *new,
34 struct list_head *prev,
35 struct list_head *next)
44 * list_add - add a new entry
45 * @new: new entry to be added
46 * @head: list head to add it after
48 * Insert a new entry after the specified head.
49 * This is good for implementing stacks.
51 static inline void list_add(struct list_head *new, struct list_head *head)
53 __list_add(new, head, head->next);
57 * list_add_tail - add a new entry
58 * @new: new entry to be added
59 * @head: list head to add it before
61 * Insert a new entry before the specified head.
62 * This is useful for implementing queues.
64 static inline void list_add_tail(struct list_head *new, struct list_head *head)
66 __list_add(new, head->prev, head);
70 * Delete a list entry by making the prev/next entries
71 * point to each other.
73 * This is only for internal list manipulation where we know
74 * the prev/next entries already!
76 static inline void __list_del(struct list_head * prev, struct list_head * next)
83 * list_del - deletes entry from list.
84 * @entry: the element to delete from the list.
85 * Note: list_empty on entry does not return true after this, the entry is
86 * in an undefined state.
88 static inline void list_del(struct list_head *entry)
90 __list_del(entry->prev, entry->next);
91 entry->next = LIST_POISON1;
92 entry->prev = LIST_POISON2;
96 * __list_for_each - iterate over a list
97 * @pos: the &struct list_head to use as a loop counter.
98 * @head: the head for your list.
100 * This variant differs from list_for_each() in that it's the
101 * simplest possible list iteration code, no prefetching is done.
102 * Use this for code that knows the list to be very short (empty
103 * or 1 entry) most of the time.
105 #define __list_for_each(pos, head) \
106 for (pos = (head)->next; pos != (head); pos = pos->next)
109 * list_for_each_safe - iterate over a list safe against removal of list entry
110 * @pos: the &struct list_head to use as a loop counter.
111 * @n: another &struct list_head to use as temporary storage
112 * @head: the head for your list.
114 #define list_for_each_safe(pos, n, head) \
115 for (pos = (head)->next, n = pos->next; pos != (head); \
116 pos = n, n = pos->next)
119 * list_entry - get the struct for this entry
120 * @ptr: the &struct list_head pointer.
121 * @type: the type of the struct this is embedded in.
122 * @member: the name of the list_struct within the struct.
124 #define list_entry(ptr, type, member) \
125 container_of(ptr, type, member)
127 static inline int list_len(struct list_head *head_p)
132 __list_for_each(p, head_p) {
140 * list_empty - tests whether a list is empty
141 * @head: the list to test.
143 static inline int list_empty(const struct list_head *head)
145 return head->next == head;
149 * list_first - Returns first entry on list, or NULL if empty
152 static inline struct list_head *list_first(const struct list_head *head)
154 return list_empty(head) ? NULL : head->next;
158 * list_move_tail - delete from one list and add as another's tail
159 * @list: the entry to move
160 * @head: the head that will follow our entry
162 static inline void list_move_tail(struct list_head *list,
163 struct list_head *head)
165 __list_del(list->prev, list->next);
166 list_add_tail(list, head);