17f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
27f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define POISON_POINTER_DELTA 0
33c85e737308ef95629b232745d6a8d141d87cc9aJP Abgrall#define LIST_POISON1  ((void *) (0x00100100 + POISON_POINTER_DELTA))
43c85e737308ef95629b232745d6a8d141d87cc9aJP Abgrall#define LIST_POISON2  ((void *) (0x00200200 + POISON_POINTER_DELTA))
57f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
63c85e737308ef95629b232745d6a8d141d87cc9aJP Abgrall#if !defined(offsetof)
77f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
83c85e737308ef95629b232745d6a8d141d87cc9aJP Abgrall#endif
97f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define container_of(ptr, type, member) ({                      \
107f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee		const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
117f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee		(type *)( (char *)__mptr - offsetof(type,member) );})
127f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
137f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestruct list_head {
147f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	struct list_head *next, *prev;
157f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee};
167f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
177f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define LIST_HEAD_INIT(name) { &(name), &(name) }
187f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
197f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define LIST_HEAD(name) \
207f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	struct list_head name = LIST_HEAD_INIT(name)
217f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
227f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void INIT_LIST_HEAD(struct list_head *list)
237f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
247f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	list->next = list;
257f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	list->prev = list;
267f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
277f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
287f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void __list_add(struct list_head *new,
297f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee		struct list_head *prev,
307f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee		struct list_head *next)
317f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
327f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	next->prev = new;
337f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	new->next = next;
347f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	new->prev = prev;
357f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	prev->next = new;
367f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
377f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
387f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void list_add(struct list_head *new, struct list_head *head)
397f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
407f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	__list_add(new, head, head->next);
417f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
427f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
437f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void list_add_tail(struct list_head *new, struct list_head *head)
447f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
457f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	__list_add(new, head->prev, head);
467f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
477f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
487f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void __list_del(struct list_head * prev, struct list_head * next)
497f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
507f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	next->prev = prev;
517f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	prev->next = next;
527f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
537f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
547f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void __list_del_entry(struct list_head *entry)
557f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
567f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	__list_del(entry->prev, entry->next);
577f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
587f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
597f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline void list_del(struct list_head *entry)
607f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
617f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	__list_del(entry->prev, entry->next);
627f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	entry->next = LIST_POISON1;
637f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	entry->prev = LIST_POISON2;
647f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
657f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
667f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Leestatic inline int list_empty(const struct list_head *head)
677f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee{
687f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	return head->next == head;
697f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee}
707f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
717f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define list_entry(ptr, type, member) \
727f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	container_of(ptr, type, member)
737f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
747f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define list_for_each(pos, head) \
757f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	for (pos = (head)->next; pos != (head); pos = pos->next)
767f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee
777f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define list_for_each_safe(pos, n, head) \
787f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	for (pos = (head)->next, n = pos->next; pos != (head); \
797f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			pos = n, n = pos->next)
807f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define list_for_each_entry(pos, head, member)                          \
817f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	for (pos = list_entry((head)->next, typeof(*pos), member);      \
827f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			&pos->member != (head);    \
837f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			pos = list_entry(pos->member.next, typeof(*pos), member))
847f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee#define list_for_each_entry_safe(pos, n, head, member)                  \
857f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee	for (pos = list_entry((head)->next, typeof(*pos), member),      \
867f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			n = list_entry(pos->member.next, typeof(*pos), member); \
877f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			&pos->member != (head);                                    \
887f35b548d4b0e3c8577ad7a09433e589a0ab3f2aChangman Lee			pos = n, n = list_entry(n->member.next, typeof(*n), member))
89