linux_list.h 23 KB

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