Commit 04254730 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Torvalds

list: introduce list_is_head() helper and re-use it in list.h

Introduce list_is_head() in the similar (*) way as it's done for
list_entry_is_head().  Make use of it in the list.h.

*) it's done as inliner and not a macro to be aligned with other
   list_is_*() APIs; while at it, make all three to have the same
   style.

Link: https://lkml.kernel.org/r/20211201141824.81400-1-andriy.shevchenko@linux.intel.comSigned-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 70ac6992
...@@ -258,8 +258,7 @@ static inline void list_bulk_move_tail(struct list_head *head, ...@@ -258,8 +258,7 @@ static inline void list_bulk_move_tail(struct list_head *head,
* @list: the entry to test * @list: the entry to test
* @head: the head of the list * @head: the head of the list
*/ */
static inline int list_is_first(const struct list_head *list, static inline int list_is_first(const struct list_head *list, const struct list_head *head)
const struct list_head *head)
{ {
return list->prev == head; return list->prev == head;
} }
...@@ -269,12 +268,21 @@ static inline int list_is_first(const struct list_head *list, ...@@ -269,12 +268,21 @@ static inline int list_is_first(const struct list_head *list,
* @list: the entry to test * @list: the entry to test
* @head: the head of the list * @head: the head of the list
*/ */
static inline int list_is_last(const struct list_head *list, static inline int list_is_last(const struct list_head *list, const struct list_head *head)
const struct list_head *head)
{ {
return list->next == head; return list->next == head;
} }
/**
* list_is_head - tests whether @list is the list @head
* @list: the entry to test
* @head: the head of the list
*/
static inline int list_is_head(const struct list_head *list, const struct list_head *head)
{
return list == head;
}
/** /**
* list_empty - tests whether a list is empty * list_empty - tests whether a list is empty
* @head: the list to test. * @head: the list to test.
...@@ -318,7 +326,7 @@ static inline void list_del_init_careful(struct list_head *entry) ...@@ -318,7 +326,7 @@ static inline void list_del_init_careful(struct list_head *entry)
static inline int list_empty_careful(const struct list_head *head) static inline int list_empty_careful(const struct list_head *head)
{ {
struct list_head *next = smp_load_acquire(&head->next); struct list_head *next = smp_load_acquire(&head->next);
return (next == head) && (next == head->prev); return list_is_head(next, head) && (next == head->prev);
} }
/** /**
...@@ -393,10 +401,9 @@ static inline void list_cut_position(struct list_head *list, ...@@ -393,10 +401,9 @@ static inline void list_cut_position(struct list_head *list,
{ {
if (list_empty(head)) if (list_empty(head))
return; return;
if (list_is_singular(head) && if (list_is_singular(head) && !list_is_head(entry, head) && (entry != head->next))
(head->next != entry && head != entry))
return; return;
if (entry == head) if (list_is_head(entry, head))
INIT_LIST_HEAD(list); INIT_LIST_HEAD(list);
else else
__list_cut_position(list, head, entry); __list_cut_position(list, head, entry);
...@@ -570,7 +577,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -570,7 +577,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each(pos, head) \ #define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next) for (pos = (head)->next; !list_is_head(pos, (head)); pos = pos->next)
/** /**
* list_for_each_continue - continue iteration over a list * list_for_each_continue - continue iteration over a list
...@@ -580,7 +587,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -580,7 +587,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* Continue to iterate over a list, continuing after the current position. * Continue to iterate over a list, continuing after the current position.
*/ */
#define list_for_each_continue(pos, head) \ #define list_for_each_continue(pos, head) \
for (pos = pos->next; pos != (head); pos = pos->next) for (pos = pos->next; !list_is_head(pos, (head)); pos = pos->next)
/** /**
* list_for_each_prev - iterate over a list backwards * list_for_each_prev - iterate over a list backwards
...@@ -588,7 +595,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -588,7 +595,7 @@ static inline void list_splice_tail_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each_prev(pos, head) \ #define list_for_each_prev(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev) for (pos = (head)->prev; !list_is_head(pos, (head)); pos = pos->prev)
/** /**
* list_for_each_safe - iterate over a list safe against removal of list entry * list_for_each_safe - iterate over a list safe against removal of list entry
...@@ -597,7 +604,8 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -597,7 +604,8 @@ static inline void list_splice_tail_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each_safe(pos, n, head) \ #define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \ for (pos = (head)->next, n = pos->next; \
!list_is_head(pos, (head)); \
pos = n, n = pos->next) pos = n, n = pos->next)
/** /**
...@@ -608,7 +616,7 @@ static inline void list_splice_tail_init(struct list_head *list, ...@@ -608,7 +616,7 @@ static inline void list_splice_tail_init(struct list_head *list,
*/ */
#define list_for_each_prev_safe(pos, n, head) \ #define list_for_each_prev_safe(pos, n, head) \
for (pos = (head)->prev, n = pos->prev; \ for (pos = (head)->prev, n = pos->prev; \
pos != (head); \ !list_is_head(pos, (head)); \
pos = n, n = pos->prev) pos = n, n = pos->prev)
/** /**
......
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