Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __TOOLS_LINUX_LIST_H
0003 #define __TOOLS_LINUX_LIST_H
0004 
0005 #include <linux/types.h>
0006 #include <linux/poison.h>
0007 #include <linux/kernel.h>
0008 #include <linux/compiler.h>
0009 
0010 /*
0011  * Simple doubly linked list implementation.
0012  *
0013  * Some of the internal functions ("__xxx") are useful when
0014  * manipulating whole lists rather than single entries, as
0015  * sometimes we already know the next/prev entries and we can
0016  * generate better code by using them directly rather than
0017  * using the generic single-entry routines.
0018  */
0019 
0020 #define LIST_HEAD_INIT(name) { &(name), &(name) }
0021 
0022 #define LIST_HEAD(name) \
0023     struct list_head name = LIST_HEAD_INIT(name)
0024 
0025 static inline void INIT_LIST_HEAD(struct list_head *list)
0026 {
0027     list->next = list;
0028     list->prev = list;
0029 }
0030 
0031 /*
0032  * Insert a new entry between two known consecutive entries.
0033  *
0034  * This is only for internal list manipulation where we know
0035  * the prev/next entries already!
0036  */
0037 #ifndef CONFIG_DEBUG_LIST
0038 static inline void __list_add(struct list_head *new,
0039                   struct list_head *prev,
0040                   struct list_head *next)
0041 {
0042     next->prev = new;
0043     new->next = next;
0044     new->prev = prev;
0045     prev->next = new;
0046 }
0047 #else
0048 extern void __list_add(struct list_head *new,
0049                   struct list_head *prev,
0050                   struct list_head *next);
0051 #endif
0052 
0053 /**
0054  * list_add - add a new entry
0055  * @new: new entry to be added
0056  * @head: list head to add it after
0057  *
0058  * Insert a new entry after the specified head.
0059  * This is good for implementing stacks.
0060  */
0061 static inline void list_add(struct list_head *new, struct list_head *head)
0062 {
0063     __list_add(new, head, head->next);
0064 }
0065 
0066 
0067 /**
0068  * list_add_tail - add a new entry
0069  * @new: new entry to be added
0070  * @head: list head to add it before
0071  *
0072  * Insert a new entry before the specified head.
0073  * This is useful for implementing queues.
0074  */
0075 static inline void list_add_tail(struct list_head *new, struct list_head *head)
0076 {
0077     __list_add(new, head->prev, head);
0078 }
0079 
0080 /*
0081  * Delete a list entry by making the prev/next entries
0082  * point to each other.
0083  *
0084  * This is only for internal list manipulation where we know
0085  * the prev/next entries already!
0086  */
0087 static inline void __list_del(struct list_head * prev, struct list_head * next)
0088 {
0089     next->prev = prev;
0090     WRITE_ONCE(prev->next, next);
0091 }
0092 
0093 /**
0094  * list_del - deletes entry from list.
0095  * @entry: the element to delete from the list.
0096  * Note: list_empty() on entry does not return true after this, the entry is
0097  * in an undefined state.
0098  */
0099 #ifndef CONFIG_DEBUG_LIST
0100 static inline void __list_del_entry(struct list_head *entry)
0101 {
0102     __list_del(entry->prev, entry->next);
0103 }
0104 
0105 static inline void list_del(struct list_head *entry)
0106 {
0107     __list_del(entry->prev, entry->next);
0108     entry->next = LIST_POISON1;
0109     entry->prev = LIST_POISON2;
0110 }
0111 #else
0112 extern void __list_del_entry(struct list_head *entry);
0113 extern void list_del(struct list_head *entry);
0114 #endif
0115 
0116 /**
0117  * list_replace - replace old entry by new one
0118  * @old : the element to be replaced
0119  * @new : the new element to insert
0120  *
0121  * If @old was empty, it will be overwritten.
0122  */
0123 static inline void list_replace(struct list_head *old,
0124                 struct list_head *new)
0125 {
0126     new->next = old->next;
0127     new->next->prev = new;
0128     new->prev = old->prev;
0129     new->prev->next = new;
0130 }
0131 
0132 static inline void list_replace_init(struct list_head *old,
0133                     struct list_head *new)
0134 {
0135     list_replace(old, new);
0136     INIT_LIST_HEAD(old);
0137 }
0138 
0139 /**
0140  * list_del_init - deletes entry from list and reinitialize it.
0141  * @entry: the element to delete from the list.
0142  */
0143 static inline void list_del_init(struct list_head *entry)
0144 {
0145     __list_del_entry(entry);
0146     INIT_LIST_HEAD(entry);
0147 }
0148 
0149 /**
0150  * list_move - delete from one list and add as another's head
0151  * @list: the entry to move
0152  * @head: the head that will precede our entry
0153  */
0154 static inline void list_move(struct list_head *list, struct list_head *head)
0155 {
0156     __list_del_entry(list);
0157     list_add(list, head);
0158 }
0159 
0160 /**
0161  * list_move_tail - delete from one list and add as another's tail
0162  * @list: the entry to move
0163  * @head: the head that will follow our entry
0164  */
0165 static inline void list_move_tail(struct list_head *list,
0166                   struct list_head *head)
0167 {
0168     __list_del_entry(list);
0169     list_add_tail(list, head);
0170 }
0171 
0172 /**
0173  * list_is_last - tests whether @list is the last entry in list @head
0174  * @list: the entry to test
0175  * @head: the head of the list
0176  */
0177 static inline int list_is_last(const struct list_head *list,
0178                 const struct list_head *head)
0179 {
0180     return list->next == head;
0181 }
0182 
0183 /**
0184  * list_empty - tests whether a list is empty
0185  * @head: the list to test.
0186  */
0187 static inline int list_empty(const struct list_head *head)
0188 {
0189     return head->next == head;
0190 }
0191 
0192 /**
0193  * list_empty_careful - tests whether a list is empty and not being modified
0194  * @head: the list to test
0195  *
0196  * Description:
0197  * tests whether a list is empty _and_ checks that no other CPU might be
0198  * in the process of modifying either member (next or prev)
0199  *
0200  * NOTE: using list_empty_careful() without synchronization
0201  * can only be safe if the only activity that can happen
0202  * to the list entry is list_del_init(). Eg. it cannot be used
0203  * if another CPU could re-list_add() it.
0204  */
0205 static inline int list_empty_careful(const struct list_head *head)
0206 {
0207     struct list_head *next = head->next;
0208     return (next == head) && (next == head->prev);
0209 }
0210 
0211 /**
0212  * list_rotate_left - rotate the list to the left
0213  * @head: the head of the list
0214  */
0215 static inline void list_rotate_left(struct list_head *head)
0216 {
0217     struct list_head *first;
0218 
0219     if (!list_empty(head)) {
0220         first = head->next;
0221         list_move_tail(first, head);
0222     }
0223 }
0224 
0225 /**
0226  * list_is_singular - tests whether a list has just one entry.
0227  * @head: the list to test.
0228  */
0229 static inline int list_is_singular(const struct list_head *head)
0230 {
0231     return !list_empty(head) && (head->next == head->prev);
0232 }
0233 
0234 static inline void __list_cut_position(struct list_head *list,
0235         struct list_head *head, struct list_head *entry)
0236 {
0237     struct list_head *new_first = entry->next;
0238     list->next = head->next;
0239     list->next->prev = list;
0240     list->prev = entry;
0241     entry->next = list;
0242     head->next = new_first;
0243     new_first->prev = head;
0244 }
0245 
0246 /**
0247  * list_cut_position - cut a list into two
0248  * @list: a new list to add all removed entries
0249  * @head: a list with entries
0250  * @entry: an entry within head, could be the head itself
0251  *  and if so we won't cut the list
0252  *
0253  * This helper moves the initial part of @head, up to and
0254  * including @entry, from @head to @list. You should
0255  * pass on @entry an element you know is on @head. @list
0256  * should be an empty list or a list you do not care about
0257  * losing its data.
0258  *
0259  */
0260 static inline void list_cut_position(struct list_head *list,
0261         struct list_head *head, struct list_head *entry)
0262 {
0263     if (list_empty(head))
0264         return;
0265     if (list_is_singular(head) &&
0266         (head->next != entry && head != entry))
0267         return;
0268     if (entry == head)
0269         INIT_LIST_HEAD(list);
0270     else
0271         __list_cut_position(list, head, entry);
0272 }
0273 
0274 static inline void __list_splice(const struct list_head *list,
0275                  struct list_head *prev,
0276                  struct list_head *next)
0277 {
0278     struct list_head *first = list->next;
0279     struct list_head *last = list->prev;
0280 
0281     first->prev = prev;
0282     prev->next = first;
0283 
0284     last->next = next;
0285     next->prev = last;
0286 }
0287 
0288 /**
0289  * list_splice - join two lists, this is designed for stacks
0290  * @list: the new list to add.
0291  * @head: the place to add it in the first list.
0292  */
0293 static inline void list_splice(const struct list_head *list,
0294                 struct list_head *head)
0295 {
0296     if (!list_empty(list))
0297         __list_splice(list, head, head->next);
0298 }
0299 
0300 /**
0301  * list_splice_tail - join two lists, each list being a queue
0302  * @list: the new list to add.
0303  * @head: the place to add it in the first list.
0304  */
0305 static inline void list_splice_tail(struct list_head *list,
0306                 struct list_head *head)
0307 {
0308     if (!list_empty(list))
0309         __list_splice(list, head->prev, head);
0310 }
0311 
0312 /**
0313  * list_splice_init - join two lists and reinitialise the emptied list.
0314  * @list: the new list to add.
0315  * @head: the place to add it in the first list.
0316  *
0317  * The list at @list is reinitialised
0318  */
0319 static inline void list_splice_init(struct list_head *list,
0320                     struct list_head *head)
0321 {
0322     if (!list_empty(list)) {
0323         __list_splice(list, head, head->next);
0324         INIT_LIST_HEAD(list);
0325     }
0326 }
0327 
0328 /**
0329  * list_splice_tail_init - join two lists and reinitialise the emptied list
0330  * @list: the new list to add.
0331  * @head: the place to add it in the first list.
0332  *
0333  * Each of the lists is a queue.
0334  * The list at @list is reinitialised
0335  */
0336 static inline void list_splice_tail_init(struct list_head *list,
0337                      struct list_head *head)
0338 {
0339     if (!list_empty(list)) {
0340         __list_splice(list, head->prev, head);
0341         INIT_LIST_HEAD(list);
0342     }
0343 }
0344 
0345 /**
0346  * list_entry - get the struct for this entry
0347  * @ptr:    the &struct list_head pointer.
0348  * @type:   the type of the struct this is embedded in.
0349  * @member: the name of the list_head within the struct.
0350  */
0351 #define list_entry(ptr, type, member) \
0352     container_of(ptr, type, member)
0353 
0354 /**
0355  * list_first_entry - get the first element from a list
0356  * @ptr:    the list head to take the element from.
0357  * @type:   the type of the struct this is embedded in.
0358  * @member: the name of the list_head within the struct.
0359  *
0360  * Note, that list is expected to be not empty.
0361  */
0362 #define list_first_entry(ptr, type, member) \
0363     list_entry((ptr)->next, type, member)
0364 
0365 /**
0366  * list_last_entry - get the last element from a list
0367  * @ptr:    the list head to take the element from.
0368  * @type:   the type of the struct this is embedded in.
0369  * @member: the name of the list_head within the struct.
0370  *
0371  * Note, that list is expected to be not empty.
0372  */
0373 #define list_last_entry(ptr, type, member) \
0374     list_entry((ptr)->prev, type, member)
0375 
0376 /**
0377  * list_first_entry_or_null - get the first element from a list
0378  * @ptr:    the list head to take the element from.
0379  * @type:   the type of the struct this is embedded in.
0380  * @member: the name of the list_head within the struct.
0381  *
0382  * Note that if the list is empty, it returns NULL.
0383  */
0384 #define list_first_entry_or_null(ptr, type, member) \
0385     (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
0386 
0387 /**
0388  * list_last_entry_or_null - get the last element from a list
0389  * @ptr:       the list head to take the element from.
0390  * @type:      the type of the struct this is embedded in.
0391  * @member:    the name of the list_head within the struct.
0392  *
0393  * Note that if the list is empty, it returns NULL.
0394  */
0395 #define list_last_entry_or_null(ptr, type, member) \
0396     (!list_empty(ptr) ? list_last_entry(ptr, type, member) : NULL)
0397 
0398 /**
0399  * list_next_entry - get the next element in list
0400  * @pos:    the type * to cursor
0401  * @member: the name of the list_head within the struct.
0402  */
0403 #define list_next_entry(pos, member) \
0404     list_entry((pos)->member.next, typeof(*(pos)), member)
0405 
0406 /**
0407  * list_prev_entry - get the prev element in list
0408  * @pos:    the type * to cursor
0409  * @member: the name of the list_head within the struct.
0410  */
0411 #define list_prev_entry(pos, member) \
0412     list_entry((pos)->member.prev, typeof(*(pos)), member)
0413 
0414 /**
0415  * list_for_each    -   iterate over a list
0416  * @pos:    the &struct list_head to use as a loop cursor.
0417  * @head:   the head for your list.
0418  */
0419 #define list_for_each(pos, head) \
0420     for (pos = (head)->next; pos != (head); pos = pos->next)
0421 
0422 /**
0423  * list_for_each_prev   -   iterate over a list backwards
0424  * @pos:    the &struct list_head to use as a loop cursor.
0425  * @head:   the head for your list.
0426  */
0427 #define list_for_each_prev(pos, head) \
0428     for (pos = (head)->prev; pos != (head); pos = pos->prev)
0429 
0430 /**
0431  * list_for_each_safe - iterate over a list safe against removal of list entry
0432  * @pos:    the &struct list_head to use as a loop cursor.
0433  * @n:      another &struct list_head to use as temporary storage
0434  * @head:   the head for your list.
0435  */
0436 #define list_for_each_safe(pos, n, head) \
0437     for (pos = (head)->next, n = pos->next; pos != (head); \
0438         pos = n, n = pos->next)
0439 
0440 /**
0441  * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
0442  * @pos:    the &struct list_head to use as a loop cursor.
0443  * @n:      another &struct list_head to use as temporary storage
0444  * @head:   the head for your list.
0445  */
0446 #define list_for_each_prev_safe(pos, n, head) \
0447     for (pos = (head)->prev, n = pos->prev; \
0448          pos != (head); \
0449          pos = n, n = pos->prev)
0450 
0451 /**
0452  * list_for_each_entry  -   iterate over list of given type
0453  * @pos:    the type * to use as a loop cursor.
0454  * @head:   the head for your list.
0455  * @member: the name of the list_head within the struct.
0456  */
0457 #define list_for_each_entry(pos, head, member)              \
0458     for (pos = list_first_entry(head, typeof(*pos), member);    \
0459          &pos->member != (head);                    \
0460          pos = list_next_entry(pos, member))
0461 
0462 /**
0463  * list_for_each_entry_reverse - iterate backwards over list of given type.
0464  * @pos:    the type * to use as a loop cursor.
0465  * @head:   the head for your list.
0466  * @member: the name of the list_head within the struct.
0467  */
0468 #define list_for_each_entry_reverse(pos, head, member)          \
0469     for (pos = list_last_entry(head, typeof(*pos), member);     \
0470          &pos->member != (head);                    \
0471          pos = list_prev_entry(pos, member))
0472 
0473 /**
0474  * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
0475  * @pos:    the type * to use as a start point
0476  * @head:   the head of the list
0477  * @member: the name of the list_head within the struct.
0478  *
0479  * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
0480  */
0481 #define list_prepare_entry(pos, head, member) \
0482     ((pos) ? : list_entry(head, typeof(*pos), member))
0483 
0484 /**
0485  * list_for_each_entry_continue - continue iteration over list of given type
0486  * @pos:    the type * to use as a loop cursor.
0487  * @head:   the head for your list.
0488  * @member: the name of the list_head within the struct.
0489  *
0490  * Continue to iterate over list of given type, continuing after
0491  * the current position.
0492  */
0493 #define list_for_each_entry_continue(pos, head, member)         \
0494     for (pos = list_next_entry(pos, member);            \
0495          &pos->member != (head);                    \
0496          pos = list_next_entry(pos, member))
0497 
0498 /**
0499  * list_for_each_entry_continue_reverse - iterate backwards from the given point
0500  * @pos:    the type * to use as a loop cursor.
0501  * @head:   the head for your list.
0502  * @member: the name of the list_head within the struct.
0503  *
0504  * Start to iterate over list of given type backwards, continuing after
0505  * the current position.
0506  */
0507 #define list_for_each_entry_continue_reverse(pos, head, member)     \
0508     for (pos = list_prev_entry(pos, member);            \
0509          &pos->member != (head);                    \
0510          pos = list_prev_entry(pos, member))
0511 
0512 /**
0513  * list_for_each_entry_from - iterate over list of given type from the current point
0514  * @pos:    the type * to use as a loop cursor.
0515  * @head:   the head for your list.
0516  * @member: the name of the list_head within the struct.
0517  *
0518  * Iterate over list of given type, continuing from current position.
0519  */
0520 #define list_for_each_entry_from(pos, head, member)             \
0521     for (; &pos->member != (head);                  \
0522          pos = list_next_entry(pos, member))
0523 
0524 /**
0525  * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
0526  * @pos:    the type * to use as a loop cursor.
0527  * @n:      another type * to use as temporary storage
0528  * @head:   the head for your list.
0529  * @member: the name of the list_head within the struct.
0530  */
0531 #define list_for_each_entry_safe(pos, n, head, member)          \
0532     for (pos = list_first_entry(head, typeof(*pos), member),    \
0533         n = list_next_entry(pos, member);           \
0534          &pos->member != (head);                    \
0535          pos = n, n = list_next_entry(n, member))
0536 
0537 /**
0538  * list_for_each_entry_safe_continue - continue list iteration safe against removal
0539  * @pos:    the type * to use as a loop cursor.
0540  * @n:      another type * to use as temporary storage
0541  * @head:   the head for your list.
0542  * @member: the name of the list_head within the struct.
0543  *
0544  * Iterate over list of given type, continuing after current point,
0545  * safe against removal of list entry.
0546  */
0547 #define list_for_each_entry_safe_continue(pos, n, head, member)         \
0548     for (pos = list_next_entry(pos, member),                \
0549         n = list_next_entry(pos, member);               \
0550          &pos->member != (head);                        \
0551          pos = n, n = list_next_entry(n, member))
0552 
0553 /**
0554  * list_for_each_entry_safe_from - iterate over list from current point safe against removal
0555  * @pos:    the type * to use as a loop cursor.
0556  * @n:      another type * to use as temporary storage
0557  * @head:   the head for your list.
0558  * @member: the name of the list_head within the struct.
0559  *
0560  * Iterate over list of given type from current point, safe against
0561  * removal of list entry.
0562  */
0563 #define list_for_each_entry_safe_from(pos, n, head, member)             \
0564     for (n = list_next_entry(pos, member);                  \
0565          &pos->member != (head);                        \
0566          pos = n, n = list_next_entry(n, member))
0567 
0568 /**
0569  * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
0570  * @pos:    the type * to use as a loop cursor.
0571  * @n:      another type * to use as temporary storage
0572  * @head:   the head for your list.
0573  * @member: the name of the list_head within the struct.
0574  *
0575  * Iterate backwards over list of given type, safe against removal
0576  * of list entry.
0577  */
0578 #define list_for_each_entry_safe_reverse(pos, n, head, member)      \
0579     for (pos = list_last_entry(head, typeof(*pos), member),     \
0580         n = list_prev_entry(pos, member);           \
0581          &pos->member != (head);                    \
0582          pos = n, n = list_prev_entry(n, member))
0583 
0584 /**
0585  * list_safe_reset_next - reset a stale list_for_each_entry_safe loop
0586  * @pos:    the loop cursor used in the list_for_each_entry_safe loop
0587  * @n:      temporary storage used in list_for_each_entry_safe
0588  * @member: the name of the list_head within the struct.
0589  *
0590  * list_safe_reset_next is not safe to use in general if the list may be
0591  * modified concurrently (eg. the lock is dropped in the loop body). An
0592  * exception to this is if the cursor element (pos) is pinned in the list,
0593  * and list_safe_reset_next is called after re-taking the lock and before
0594  * completing the current iteration of the loop body.
0595  */
0596 #define list_safe_reset_next(pos, n, member)                \
0597     n = list_next_entry(pos, member)
0598 
0599 /*
0600  * Double linked lists with a single pointer list head.
0601  * Mostly useful for hash tables where the two pointer list head is
0602  * too wasteful.
0603  * You lose the ability to access the tail in O(1).
0604  */
0605 
0606 #define HLIST_HEAD_INIT { .first = NULL }
0607 #define HLIST_HEAD(name) struct hlist_head name = {  .first = NULL }
0608 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
0609 static inline void INIT_HLIST_NODE(struct hlist_node *h)
0610 {
0611     h->next = NULL;
0612     h->pprev = NULL;
0613 }
0614 
0615 static inline int hlist_unhashed(const struct hlist_node *h)
0616 {
0617     return !h->pprev;
0618 }
0619 
0620 static inline int hlist_empty(const struct hlist_head *h)
0621 {
0622     return !h->first;
0623 }
0624 
0625 static inline void __hlist_del(struct hlist_node *n)
0626 {
0627     struct hlist_node *next = n->next;
0628     struct hlist_node **pprev = n->pprev;
0629 
0630     WRITE_ONCE(*pprev, next);
0631     if (next)
0632         next->pprev = pprev;
0633 }
0634 
0635 static inline void hlist_del(struct hlist_node *n)
0636 {
0637     __hlist_del(n);
0638     n->next = LIST_POISON1;
0639     n->pprev = LIST_POISON2;
0640 }
0641 
0642 static inline void hlist_del_init(struct hlist_node *n)
0643 {
0644     if (!hlist_unhashed(n)) {
0645         __hlist_del(n);
0646         INIT_HLIST_NODE(n);
0647     }
0648 }
0649 
0650 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
0651 {
0652     struct hlist_node *first = h->first;
0653     n->next = first;
0654     if (first)
0655         first->pprev = &n->next;
0656     h->first = n;
0657     n->pprev = &h->first;
0658 }
0659 
0660 /* next must be != NULL */
0661 static inline void hlist_add_before(struct hlist_node *n,
0662                     struct hlist_node *next)
0663 {
0664     n->pprev = next->pprev;
0665     n->next = next;
0666     next->pprev = &n->next;
0667     *(n->pprev) = n;
0668 }
0669 
0670 static inline void hlist_add_behind(struct hlist_node *n,
0671                     struct hlist_node *prev)
0672 {
0673     n->next = prev->next;
0674     prev->next = n;
0675     n->pprev = &prev->next;
0676 
0677     if (n->next)
0678         n->next->pprev  = &n->next;
0679 }
0680 
0681 /* after that we'll appear to be on some hlist and hlist_del will work */
0682 static inline void hlist_add_fake(struct hlist_node *n)
0683 {
0684     n->pprev = &n->next;
0685 }
0686 
0687 static inline bool hlist_fake(struct hlist_node *h)
0688 {
0689     return h->pprev == &h->next;
0690 }
0691 
0692 /*
0693  * Move a list from one list head to another. Fixup the pprev
0694  * reference of the first entry if it exists.
0695  */
0696 static inline void hlist_move_list(struct hlist_head *old,
0697                    struct hlist_head *new)
0698 {
0699     new->first = old->first;
0700     if (new->first)
0701         new->first->pprev = &new->first;
0702     old->first = NULL;
0703 }
0704 
0705 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
0706 
0707 #define hlist_for_each(pos, head) \
0708     for (pos = (head)->first; pos ; pos = pos->next)
0709 
0710 #define hlist_for_each_safe(pos, n, head) \
0711     for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
0712          pos = n)
0713 
0714 #define hlist_entry_safe(ptr, type, member) \
0715     ({ typeof(ptr) ____ptr = (ptr); \
0716        ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
0717     })
0718 
0719 /**
0720  * hlist_for_each_entry - iterate over list of given type
0721  * @pos:    the type * to use as a loop cursor.
0722  * @head:   the head for your list.
0723  * @member: the name of the hlist_node within the struct.
0724  */
0725 #define hlist_for_each_entry(pos, head, member)             \
0726     for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
0727          pos;                           \
0728          pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
0729 
0730 /**
0731  * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
0732  * @pos:    the type * to use as a loop cursor.
0733  * @member: the name of the hlist_node within the struct.
0734  */
0735 #define hlist_for_each_entry_continue(pos, member)          \
0736     for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\
0737          pos;                           \
0738          pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
0739 
0740 /**
0741  * hlist_for_each_entry_from - iterate over a hlist continuing from current point
0742  * @pos:    the type * to use as a loop cursor.
0743  * @member: the name of the hlist_node within the struct.
0744  */
0745 #define hlist_for_each_entry_from(pos, member)              \
0746     for (; pos;                         \
0747          pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
0748 
0749 /**
0750  * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
0751  * @pos:    the type * to use as a loop cursor.
0752  * @n:      another &struct hlist_node to use as temporary storage
0753  * @head:   the head for your list.
0754  * @member: the name of the hlist_node within the struct.
0755  */
0756 #define hlist_for_each_entry_safe(pos, n, head, member)         \
0757     for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\
0758          pos && ({ n = pos->member.next; 1; });         \
0759          pos = hlist_entry_safe(n, typeof(*pos), member))
0760 
0761 /**
0762  * list_del_range - deletes range of entries from list.
0763  * @begin: first element in the range to delete from the list.
0764  * @end: last element in the range to delete from the list.
0765  * Note: list_empty on the range of entries does not return true after this,
0766  * the entries is in an undefined state.
0767  */
0768 static inline void list_del_range(struct list_head *begin,
0769                   struct list_head *end)
0770 {
0771     begin->prev->next = end->next;
0772     end->next->prev = begin->prev;
0773 }
0774 
0775 /**
0776  * list_for_each_from   -   iterate over a list from one of its nodes
0777  * @pos:  the &struct list_head to use as a loop cursor, from where to start
0778  * @head: the head for your list.
0779  */
0780 #define list_for_each_from(pos, head) \
0781     for (; pos != (head); pos = pos->next)
0782 
0783 #endif /* __TOOLS_LINUX_LIST_H */