Commit 93be3c2e authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

list: introduce list_last_entry(), use list_{first,last}_entry()

We already have list_first_entry(), it makes sense to also add
list_last_entry() for consistency.  And we use both helpers in
list_for_each_*().
Signed-off-by: default avatarOleg Nesterov <oleg@redhat.com>
Cc: Eilon Greenstein <eilong@broadcom.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8120e2e5
...@@ -361,6 +361,17 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -361,6 +361,17 @@ static inline void list_splice_tail_init(struct list_head *list,
#define list_first_entry(ptr, type, member) \ #define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member) list_entry((ptr)->next, type, member)
/**
* list_last_entry - get the last element from a list
* @ptr: the list head to take the element from.
* @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct.
*
* Note, that list is expected to be not empty.
*/
#define list_last_entry(ptr, type, member) \
list_entry((ptr)->prev, type, member)
/** /**
* list_first_entry_or_null - get the first element from a list * list_first_entry_or_null - get the first element from a list
* @ptr: the list head to take the element from. * @ptr: the list head to take the element from.
...@@ -432,7 +443,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -432,7 +443,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry(pos, head, member) \ #define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \ for (pos = list_first_entry(head, typeof(*pos), member); \
&pos->member != (head); \ &pos->member != (head); \
pos = list_next_entry(pos, member)) pos = list_next_entry(pos, member))
...@@ -443,7 +454,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -443,7 +454,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_reverse(pos, head, member) \ #define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \ for (pos = list_last_entry(head, typeof(*pos), member); \
&pos->member != (head); \ &pos->member != (head); \
pos = list_prev_entry(pos, member)) pos = list_prev_entry(pos, member))
...@@ -506,7 +517,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -506,7 +517,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_safe(pos, n, head, member) \ #define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member), \ for (pos = list_first_entry(head, typeof(*pos), member), \
n = list_next_entry(pos, member); \ n = list_next_entry(pos, member); \
&pos->member != (head); \ &pos->member != (head); \
pos = n, n = list_next_entry(n, member)) pos = n, n = list_next_entry(n, member))
...@@ -553,7 +564,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -553,7 +564,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* of list entry. * of list entry.
*/ */
#define list_for_each_entry_safe_reverse(pos, n, head, member) \ #define list_for_each_entry_safe_reverse(pos, n, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member), \ for (pos = list_last_entry(head, typeof(*pos), member), \
n = list_prev_entry(pos, member); \ n = list_prev_entry(pos, member); \
&pos->member != (head); \ &pos->member != (head); \
pos = n, n = list_prev_entry(n, member)) pos = n, n = list_prev_entry(n, member))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment