list.h 20 KB

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