diff options
Diffstat (limited to 'include/linux/list.h')
-rw-r--r-- | include/linux/list.h | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/include/linux/list.h b/include/linux/list.h index cc6d2aa6b415..d991cc147c98 100644 --- a/include/linux/list.h +++ b/include/linux/list.h | |||
@@ -666,54 +666,49 @@ static inline void hlist_move_list(struct hlist_head *old, | |||
666 | for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ | 666 | for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ |
667 | pos = n) | 667 | pos = n) |
668 | 668 | ||
669 | #define hlist_entry_safe(ptr, type, member) \ | ||
670 | (ptr) ? hlist_entry(ptr, type, member) : NULL | ||
671 | |||
669 | /** | 672 | /** |
670 | * hlist_for_each_entry - iterate over list of given type | 673 | * hlist_for_each_entry - iterate over list of given type |
671 | * @tpos: the type * to use as a loop cursor. | 674 | * @pos: the type * to use as a loop cursor. |
672 | * @pos: the &struct hlist_node to use as a loop cursor. | ||
673 | * @head: the head for your list. | 675 | * @head: the head for your list. |
674 | * @member: the name of the hlist_node within the struct. | 676 | * @member: the name of the hlist_node within the struct. |
675 | */ | 677 | */ |
676 | #define hlist_for_each_entry(tpos, pos, head, member) \ | 678 | #define hlist_for_each_entry(pos, head, member) \ |
677 | for (pos = (head)->first; \ | 679 | for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ |
678 | pos && \ | 680 | pos; \ |
679 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ | 681 | pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) |
680 | pos = pos->next) | ||
681 | 682 | ||
682 | /** | 683 | /** |
683 | * hlist_for_each_entry_continue - iterate over a hlist continuing after current point | 684 | * hlist_for_each_entry_continue - iterate over a hlist continuing after current point |
684 | * @tpos: the type * to use as a loop cursor. | 685 | * @pos: the type * to use as a loop cursor. |
685 | * @pos: the &struct hlist_node to use as a loop cursor. | ||
686 | * @member: the name of the hlist_node within the struct. | 686 | * @member: the name of the hlist_node within the struct. |
687 | */ | 687 | */ |
688 | #define hlist_for_each_entry_continue(tpos, pos, member) \ | 688 | #define hlist_for_each_entry_continue(pos, member) \ |
689 | for (pos = (pos)->next; \ | 689 | for (pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member);\ |
690 | pos && \ | 690 | pos; \ |
691 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ | 691 | pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) |
692 | pos = pos->next) | ||
693 | 692 | ||
694 | /** | 693 | /** |
695 | * hlist_for_each_entry_from - iterate over a hlist continuing from current point | 694 | * hlist_for_each_entry_from - iterate over a hlist continuing from current point |
696 | * @tpos: the type * to use as a loop cursor. | 695 | * @pos: the type * to use as a loop cursor. |
697 | * @pos: the &struct hlist_node to use as a loop cursor. | ||
698 | * @member: the name of the hlist_node within the struct. | 696 | * @member: the name of the hlist_node within the struct. |
699 | */ | 697 | */ |
700 | #define hlist_for_each_entry_from(tpos, pos, member) \ | 698 | #define hlist_for_each_entry_from(pos, member) \ |
701 | for (; pos && \ | 699 | for (; pos; \ |
702 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ | 700 | pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) |
703 | pos = pos->next) | ||
704 | 701 | ||
705 | /** | 702 | /** |
706 | * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry | 703 | * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry |
707 | * @tpos: the type * to use as a loop cursor. | 704 | * @pos: the type * to use as a loop cursor. |
708 | * @pos: the &struct hlist_node to use as a loop cursor. | ||
709 | * @n: another &struct hlist_node to use as temporary storage | 705 | * @n: another &struct hlist_node to use as temporary storage |
710 | * @head: the head for your list. | 706 | * @head: the head for your list. |
711 | * @member: the name of the hlist_node within the struct. | 707 | * @member: the name of the hlist_node within the struct. |
712 | */ | 708 | */ |
713 | #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ | 709 | #define hlist_for_each_entry_safe(pos, n, head, member) \ |
714 | for (pos = (head)->first; \ | 710 | for (pos = hlist_entry_safe((head)->first, typeof(*pos), member);\ |
715 | pos && ({ n = pos->next; 1; }) && \ | 711 | pos && ({ n = pos->member.next; 1; }); \ |
716 | ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ | 712 | pos = hlist_entry_safe(n, typeof(*pos), member)) |
717 | pos = n) | ||
718 | 713 | ||
719 | #endif | 714 | #endif |