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