list.h 20 KB

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