Skip to content

Commit

Permalink
scripts: import more list macros
Browse files Browse the repository at this point in the history
Import list_is_first, list_is_last, list_replace, and list_replace_init.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
  • Loading branch information
Sami Tolvanen authored and Masahiro Yamada committed Oct 6, 2024
1 parent 984ed20 commit c14a304
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions scripts/include/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,36 @@ static inline void list_del(struct list_head *entry)
entry->prev = LIST_POISON2;
}

/**
* list_replace - replace old entry by new one
* @old : the element to be replaced
* @new : the new element to insert
*
* If @old was empty, it will be overwritten.
*/
static inline void list_replace(struct list_head *old,
struct list_head *new)
{
new->next = old->next;
new->next->prev = new;
new->prev = old->prev;
new->prev->next = new;
}

/**
* list_replace_init - replace old entry by new one and initialize the old one
* @old : the element to be replaced
* @new : the new element to insert
*
* If @old was empty, it will be overwritten.
*/
static inline void list_replace_init(struct list_head *old,
struct list_head *new)
{
list_replace(old, new);
INIT_LIST_HEAD(old);
}

/**
* list_move - delete from one list and add as another's head
* @list: the entry to move
Expand All @@ -150,6 +180,26 @@ static inline void list_move_tail(struct list_head *list,
list_add_tail(list, head);
}

/**
* list_is_first -- tests whether @list is the first entry in list @head
* @list: the entry to test
* @head: the head of the list
*/
static inline int list_is_first(const struct list_head *list, const struct list_head *head)
{
return list->prev == head;
}

/**
* list_is_last - tests whether @list is the last entry in list @head
* @list: the entry to test
* @head: the head of the list
*/
static inline int list_is_last(const struct list_head *list, const struct list_head *head)
{
return list->next == head;
}

/**
* list_is_head - tests whether @list is the list @head
* @list: the entry to test
Expand Down

0 comments on commit c14a304

Please sign in to comment.