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