list.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  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_for_each - iterate over a list
  319. * @pos: the &struct list_head to use as a loop cursor.
  320. * @head: the head for your list.
  321. */
  322. #define list_for_each(pos, head) \
  323. for (pos = (head)->next; prefetch(pos->next), pos != (head); \
  324. pos = pos->next)
  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. * This variant differs from list_for_each() in that it's the
  331. * simplest possible list iteration code, no prefetching is done.
  332. * Use this for code that knows the list to be very short (empty
  333. * or 1 entry) most of the time.
  334. */
  335. #define __list_for_each(pos, head) \
  336. for (pos = (head)->next; pos != (head); pos = pos->next)
  337. /**
  338. * list_for_each_prev - iterate over a list backwards
  339. * @pos: the &struct list_head to use as a loop cursor.
  340. * @head: the head for your list.
  341. */
  342. #define list_for_each_prev(pos, head) \
  343. for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
  344. pos = pos->prev)
  345. /**
  346. * list_for_each_safe - iterate over a list safe against removal of list entry
  347. * @pos: the &struct list_head to use as a loop cursor.
  348. * @n: another &struct list_head to use as temporary storage
  349. * @head: the head for your list.
  350. */
  351. #define list_for_each_safe(pos, n, head) \
  352. for (pos = (head)->next, n = pos->next; pos != (head); \
  353. pos = n, n = pos->next)
  354. /**
  355. * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
  356. * @pos: the &struct list_head to use as a loop cursor.
  357. * @n: another &struct list_head to use as temporary storage
  358. * @head: the head for your list.
  359. */
  360. #define list_for_each_prev_safe(pos, n, head) \
  361. for (pos = (head)->prev, n = pos->prev; \
  362. prefetch(pos->prev), pos != (head); \
  363. pos = n, n = pos->prev)
  364. /**
  365. * list_for_each_entry - iterate over list of given type
  366. * @pos: the type * to use as a loop cursor.
  367. * @head: the head for your list.
  368. * @member: the name of the list_struct within the struct.
  369. */
  370. #define list_for_each_entry(pos, head, member) \
  371. for (pos = list_entry((head)->next, typeof(*pos), member); \
  372. prefetch(pos->member.next), &pos->member != (head); \
  373. pos = list_entry(pos->member.next, typeof(*pos), member))
  374. /**
  375. * list_for_each_entry_reverse - iterate backwards 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_reverse(pos, head, member) \
  381. for (pos = list_entry((head)->prev, typeof(*pos), member); \
  382. prefetch(pos->member.prev), &pos->member != (head); \
  383. pos = list_entry(pos->member.prev, typeof(*pos), member))
  384. /**
  385. * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
  386. * @pos: the type * to use as a start point
  387. * @head: the head of the list
  388. * @member: the name of the list_struct within the struct.
  389. *
  390. * Prepares a pos entry for use as a start point in list_for_each_entry_continue().
  391. */
  392. #define list_prepare_entry(pos, head, member) \
  393. ((pos) ? : list_entry(head, typeof(*pos), member))
  394. /**
  395. * list_for_each_entry_continue - continue iteration over list of given type
  396. * @pos: the type * to use as a loop cursor.
  397. * @head: the head for your list.
  398. * @member: the name of the list_struct within the struct.
  399. *
  400. * Continue to iterate over list of given type, continuing after
  401. * the current position.
  402. */
  403. #define list_for_each_entry_continue(pos, head, member) \
  404. for (pos = list_entry(pos->member.next, typeof(*pos), member); \
  405. prefetch(pos->member.next), &pos->member != (head); \
  406. pos = list_entry(pos->member.next, typeof(*pos), member))
  407. /**
  408. * list_for_each_entry_continue_reverse - iterate backwards from the given point
  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. * Start to iterate over list of given type backwards, continuing after
  414. * the current position.
  415. */
  416. #define list_for_each_entry_continue_reverse(pos, head, member) \
  417. for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
  418. prefetch(pos->member.prev), &pos->member != (head); \
  419. pos = list_entry(pos->member.prev, typeof(*pos), member))
  420. /**
  421. * list_for_each_entry_from - iterate over list of given type from the current 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. * Iterate over list of given type, continuing from current position.
  427. */
  428. #define list_for_each_entry_from(pos, head, member) \
  429. for (; prefetch(pos->member.next), &pos->member != (head); \
  430. pos = list_entry(pos->member.next, typeof(*pos), member))
  431. /**
  432. * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  433. * @pos: the type * to use as a loop cursor.
  434. * @n: another type * to use as temporary storage
  435. * @head: the head for your list.
  436. * @member: the name of the list_struct within the struct.
  437. */
  438. #define list_for_each_entry_safe(pos, n, head, member) \
  439. for (pos = list_entry((head)->next, typeof(*pos), member), \
  440. n = list_entry(pos->member.next, typeof(*pos), member); \
  441. &pos->member != (head); \
  442. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  443. /**
  444. * list_for_each_entry_safe_continue
  445. * @pos: the type * to use as a loop cursor.
  446. * @n: another type * to use as temporary storage
  447. * @head: the head for your list.
  448. * @member: the name of the list_struct within the struct.
  449. *
  450. * Iterate over list of given type, continuing after current point,
  451. * safe against removal of list entry.
  452. */
  453. #define list_for_each_entry_safe_continue(pos, n, head, member) \
  454. for (pos = list_entry(pos->member.next, typeof(*pos), member), \
  455. n = list_entry(pos->member.next, typeof(*pos), member); \
  456. &pos->member != (head); \
  457. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  458. /**
  459. * list_for_each_entry_safe_from
  460. * @pos: the type * to use as a loop cursor.
  461. * @n: another type * to use as temporary storage
  462. * @head: the head for your list.
  463. * @member: the name of the list_struct within the struct.
  464. *
  465. * Iterate over list of given type from current point, safe against
  466. * removal of list entry.
  467. */
  468. #define list_for_each_entry_safe_from(pos, n, head, member) \
  469. for (n = list_entry(pos->member.next, typeof(*pos), member); \
  470. &pos->member != (head); \
  471. pos = n, n = list_entry(n->member.next, typeof(*n), member))
  472. /**
  473. * list_for_each_entry_safe_reverse
  474. * @pos: the type * to use as a loop cursor.
  475. * @n: another type * to use as temporary storage
  476. * @head: the head for your list.
  477. * @member: the name of the list_struct within the struct.
  478. *
  479. * Iterate backwards over list of given type, safe against removal
  480. * of list entry.
  481. */
  482. #define list_for_each_entry_safe_reverse(pos, n, head, member) \
  483. for (pos = list_entry((head)->prev, typeof(*pos), member), \
  484. n = list_entry(pos->member.prev, typeof(*pos), member); \
  485. &pos->member != (head); \
  486. pos = n, n = list_entry(n->member.prev, typeof(*n), member))
  487. /*
  488. * Double linked lists with a single pointer list head.
  489. * Mostly useful for hash tables where the two pointer list head is
  490. * too wasteful.
  491. * You lose the ability to access the tail in O(1).
  492. */
  493. struct hlist_head {
  494. struct hlist_node *first;
  495. };
  496. struct hlist_node {
  497. struct hlist_node *next, **pprev;
  498. };
  499. #define HLIST_HEAD_INIT { .first = NULL }
  500. #define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
  501. #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
  502. static inline void INIT_HLIST_NODE(struct hlist_node *h)
  503. {
  504. h->next = NULL;
  505. h->pprev = NULL;
  506. }
  507. static inline int hlist_unhashed(const struct hlist_node *h)
  508. {
  509. return !h->pprev;
  510. }
  511. static inline int hlist_empty(const struct hlist_head *h)
  512. {
  513. return !h->first;
  514. }
  515. static inline void __hlist_del(struct hlist_node *n)
  516. {
  517. struct hlist_node *next = n->next;
  518. struct hlist_node **pprev = n->pprev;
  519. *pprev = next;
  520. if (next)
  521. next->pprev = pprev;
  522. }
  523. static inline void hlist_del(struct hlist_node *n)
  524. {
  525. __hlist_del(n);
  526. n->next = LIST_POISON1;
  527. n->pprev = LIST_POISON2;
  528. }
  529. static inline void hlist_del_init(struct hlist_node *n)
  530. {
  531. if (!hlist_unhashed(n)) {
  532. __hlist_del(n);
  533. INIT_HLIST_NODE(n);
  534. }
  535. }
  536. static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
  537. {
  538. struct hlist_node *first = h->first;
  539. n->next = first;
  540. if (first)
  541. first->pprev = &n->next;
  542. h->first = n;
  543. n->pprev = &h->first;
  544. }
  545. /* next must be != NULL */
  546. static inline void hlist_add_before(struct hlist_node *n,
  547. struct hlist_node *next)
  548. {
  549. n->pprev = next->pprev;
  550. n->next = next;
  551. next->pprev = &n->next;
  552. *(n->pprev) = n;
  553. }
  554. static inline void hlist_add_after(struct hlist_node *n,
  555. struct hlist_node *next)
  556. {
  557. next->next = n->next;
  558. n->next = next;
  559. next->pprev = &n->next;
  560. if(next->next)
  561. next->next->pprev = &next->next;
  562. }
  563. #define hlist_entry(ptr, type, member) container_of(ptr,type,member)
  564. #define hlist_for_each(pos, head) \
  565. for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
  566. pos = pos->next)
  567. #define hlist_for_each_safe(pos, n, head) \
  568. for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
  569. pos = n)
  570. /**
  571. * hlist_for_each_entry - iterate over list of given type
  572. * @tpos: the type * to use as a loop cursor.
  573. * @pos: the &struct hlist_node to use as a loop cursor.
  574. * @head: the head for your list.
  575. * @member: the name of the hlist_node within the struct.
  576. */
  577. #define hlist_for_each_entry(tpos, pos, head, member) \
  578. for (pos = (head)->first; \
  579. pos && ({ prefetch(pos->next); 1;}) && \
  580. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  581. pos = pos->next)
  582. /**
  583. * hlist_for_each_entry_continue - iterate over a hlist continuing after current point
  584. * @tpos: the type * to use as a loop cursor.
  585. * @pos: the &struct hlist_node to use as a loop cursor.
  586. * @member: the name of the hlist_node within the struct.
  587. */
  588. #define hlist_for_each_entry_continue(tpos, pos, member) \
  589. for (pos = (pos)->next; \
  590. pos && ({ prefetch(pos->next); 1;}) && \
  591. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  592. pos = pos->next)
  593. /**
  594. * hlist_for_each_entry_from - iterate over a hlist continuing from current point
  595. * @tpos: the type * to use as a loop cursor.
  596. * @pos: the &struct hlist_node to use as a loop cursor.
  597. * @member: the name of the hlist_node within the struct.
  598. */
  599. #define hlist_for_each_entry_from(tpos, pos, member) \
  600. for (; pos && ({ prefetch(pos->next); 1;}) && \
  601. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  602. pos = pos->next)
  603. /**
  604. * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
  605. * @tpos: the type * to use as a loop cursor.
  606. * @pos: the &struct hlist_node to use as a loop cursor.
  607. * @n: another &struct hlist_node to use as temporary storage
  608. * @head: the head for your list.
  609. * @member: the name of the hlist_node within the struct.
  610. */
  611. #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
  612. for (pos = (head)->first; \
  613. pos && ({ n = pos->next; 1; }) && \
  614. ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
  615. pos = n)
  616. #endif