list.h 21 KB

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