list.h 20 KB

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