diff options
author | Masahiro Yamada <masahiroy@kernel.org> | 2024-06-18 19:35:20 +0900 |
---|---|---|
committer | Masahiro Yamada <masahiroy@kernel.org> | 2024-07-16 01:08:37 +0900 |
commit | ee29e6204c32dce013ac6d1078d98dce5607ce86 (patch) | |
tree | c20b27da996299b72d8733ec53a87bbd5335342a /scripts/kconfig | |
parent | 17c31aded9a1ee87e37f0ea0e3737797ef3f8c97 (diff) |
kconfig: import list_move(_tail) and list_for_each_entry_reverse macros
Import more macros from include/linux/list.h.
These will be used in the next commit.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts/kconfig')
-rw-r--r-- | scripts/kconfig/list.h | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 882859ddf9f4..409201cd495b 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -128,6 +128,29 @@ static inline void list_del(struct list_head *entry) } /** + * list_move - delete from one list and add as another's head + * @list: the entry to move + * @head: the head that will precede our entry + */ +static inline void list_move(struct list_head *list, struct list_head *head) +{ + __list_del_entry(list); + list_add(list, head); +} + +/** + * list_move_tail - delete from one list and add as another's tail + * @list: the entry to move + * @head: the head that will follow our entry + */ +static inline void list_move_tail(struct list_head *list, + struct list_head *head) +{ + __list_del_entry(list); + list_add_tail(list, head); +} + +/** * list_is_head - tests whether @list is the list @head * @list: the entry to test * @head: the head of the list @@ -167,6 +190,17 @@ static inline int list_empty(const struct list_head *head) 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_head 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_next_entry - get the next element in list * @pos: the type * to cursor * @member: the name of the list_head within the struct. @@ -175,6 +209,14 @@ static inline int list_empty(const struct list_head *head) list_entry((pos)->member.next, typeof(*(pos)), member) /** + * list_prev_entry - get the prev element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_prev_entry(pos, member) \ + list_entry((pos)->member.prev, typeof(*(pos)), member) + +/** * list_entry_is_head - test if the entry points to the head of the list * @pos: the type * to cursor * @head: the head for your list. @@ -195,6 +237,17 @@ static inline int list_empty(const struct list_head *head) pos = list_next_entry(pos, member)) /** + * list_for_each_entry_reverse - iterate backwards over list of given type. + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_reverse(pos, head, member) \ + for (pos = list_last_entry(head, typeof(*pos), member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_prev_entry(pos, member)) + +/** * list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry * @pos: the type * to use as a loop cursor. * @n: another type * to use as temporary storage |