diff options
| author | Oleg Nesterov <oleg@redhat.com> | 2013-11-12 18:10:03 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-11-12 22:09:24 -0500 |
| commit | 93be3c2eb3371f022ad88acf1ab6bee8e3c38378 (patch) | |
| tree | 9075b8c5f48c38cc2fd11c1eba408981d8f68480 | |
| parent | 8120e2e5141a420edee725ff28f18aa264795f7a (diff) | |
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: Oleg 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | include/linux/list.h | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/include/linux/list.h b/include/linux/list.h index c88a591d1c02..ef9594171062 100644 --- a/include/linux/list.h +++ b/include/linux/list.h | |||
| @@ -362,6 +362,17 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
| 362 | list_entry((ptr)->next, type, member) | 362 | list_entry((ptr)->next, type, member) |
| 363 | 363 | ||
| 364 | /** | 364 | /** |
| 365 | * list_last_entry - get the last element from a list | ||
| 366 | * @ptr: the list head to take the element from. | ||
| 367 | * @type: the type of the struct this is embedded in. | ||
| 368 | * @member: the name of the list_struct within the struct. | ||
| 369 | * | ||
| 370 | * Note, that list is expected to be not empty. | ||
| 371 | */ | ||
| 372 | #define list_last_entry(ptr, type, member) \ | ||
| 373 | list_entry((ptr)->prev, type, member) | ||
| 374 | |||
| 375 | /** | ||
| 365 | * list_first_entry_or_null - get the first element from a list | 376 | * list_first_entry_or_null - get the first element from a list |
| 366 | * @ptr: the list head to take the element from. | 377 | * @ptr: the list head to take the element from. |
| 367 | * @type: the type of the struct this is embedded in. | 378 | * @type: the type of the struct this is embedded in. |
| @@ -432,7 +443,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
| 432 | * @member: the name of the list_struct within the struct. | 443 | * @member: the name of the list_struct within the struct. |
| 433 | */ | 444 | */ |
| 434 | #define list_for_each_entry(pos, head, member) \ | 445 | #define list_for_each_entry(pos, head, member) \ |
| 435 | for (pos = list_entry((head)->next, typeof(*pos), member); \ | 446 | for (pos = list_first_entry(head, typeof(*pos), member); \ |
| 436 | &pos->member != (head); \ | 447 | &pos->member != (head); \ |
| 437 | pos = list_next_entry(pos, member)) | 448 | pos = list_next_entry(pos, member)) |
| 438 | 449 | ||
| @@ -443,7 +454,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
| 443 | * @member: the name of the list_struct within the struct. | 454 | * @member: the name of the list_struct within the struct. |
| 444 | */ | 455 | */ |
| 445 | #define list_for_each_entry_reverse(pos, head, member) \ | 456 | #define list_for_each_entry_reverse(pos, head, member) \ |
| 446 | for (pos = list_entry((head)->prev, typeof(*pos), member); \ | 457 | for (pos = list_last_entry(head, typeof(*pos), member); \ |
| 447 | &pos->member != (head); \ | 458 | &pos->member != (head); \ |
| 448 | pos = list_prev_entry(pos, member)) | 459 | pos = list_prev_entry(pos, member)) |
| 449 | 460 | ||
| @@ -506,7 +517,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
| 506 | * @member: the name of the list_struct within the struct. | 517 | * @member: the name of the list_struct within the struct. |
| 507 | */ | 518 | */ |
| 508 | #define list_for_each_entry_safe(pos, n, head, member) \ | 519 | #define list_for_each_entry_safe(pos, n, head, member) \ |
| 509 | for (pos = list_entry((head)->next, typeof(*pos), member), \ | 520 | for (pos = list_first_entry(head, typeof(*pos), member), \ |
| 510 | n = list_next_entry(pos, member); \ | 521 | n = list_next_entry(pos, member); \ |
| 511 | &pos->member != (head); \ | 522 | &pos->member != (head); \ |
| 512 | pos = n, n = list_next_entry(n, member)) | 523 | pos = n, n = list_next_entry(n, member)) |
| @@ -553,7 +564,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
| 553 | * of list entry. | 564 | * of list entry. |
| 554 | */ | 565 | */ |
| 555 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ | 566 | #define list_for_each_entry_safe_reverse(pos, n, head, member) \ |
| 556 | for (pos = list_entry((head)->prev, typeof(*pos), member), \ | 567 | for (pos = list_last_entry(head, typeof(*pos), member), \ |
| 557 | n = list_prev_entry(pos, member); \ | 568 | n = list_prev_entry(pos, member); \ |
| 558 | &pos->member != (head); \ | 569 | &pos->member != (head); \ |
| 559 | pos = n, n = list_prev_entry(n, member)) | 570 | pos = n, n = list_prev_entry(n, member)) |
