Skip to content

Commit ee29e62

Browse files
committed
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 <[email protected]>
1 parent 17c31ad commit ee29e62

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

scripts/kconfig/list.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,29 @@ static inline void list_del(struct list_head *entry)
127127
entry->prev = LIST_POISON2;
128128
}
129129

130+
/**
131+
* list_move - delete from one list and add as another's head
132+
* @list: the entry to move
133+
* @head: the head that will precede our entry
134+
*/
135+
static inline void list_move(struct list_head *list, struct list_head *head)
136+
{
137+
__list_del_entry(list);
138+
list_add(list, head);
139+
}
140+
141+
/**
142+
* list_move_tail - delete from one list and add as another's tail
143+
* @list: the entry to move
144+
* @head: the head that will follow our entry
145+
*/
146+
static inline void list_move_tail(struct list_head *list,
147+
struct list_head *head)
148+
{
149+
__list_del_entry(list);
150+
list_add_tail(list, head);
151+
}
152+
130153
/**
131154
* list_is_head - tests whether @list is the list @head
132155
* @list: the entry to test
@@ -166,6 +189,17 @@ static inline int list_empty(const struct list_head *head)
166189
#define list_first_entry(ptr, type, member) \
167190
list_entry((ptr)->next, type, member)
168191

192+
/**
193+
* list_last_entry - get the last element from a list
194+
* @ptr: the list head to take the element from.
195+
* @type: the type of the struct this is embedded in.
196+
* @member: the name of the list_head within the struct.
197+
*
198+
* Note, that list is expected to be not empty.
199+
*/
200+
#define list_last_entry(ptr, type, member) \
201+
list_entry((ptr)->prev, type, member)
202+
169203
/**
170204
* list_next_entry - get the next element in list
171205
* @pos: the type * to cursor
@@ -174,6 +208,14 @@ static inline int list_empty(const struct list_head *head)
174208
#define list_next_entry(pos, member) \
175209
list_entry((pos)->member.next, typeof(*(pos)), member)
176210

211+
/**
212+
* list_prev_entry - get the prev element in list
213+
* @pos: the type * to cursor
214+
* @member: the name of the list_head within the struct.
215+
*/
216+
#define list_prev_entry(pos, member) \
217+
list_entry((pos)->member.prev, typeof(*(pos)), member)
218+
177219
/**
178220
* list_entry_is_head - test if the entry points to the head of the list
179221
* @pos: the type * to cursor
@@ -194,6 +236,17 @@ static inline int list_empty(const struct list_head *head)
194236
!list_entry_is_head(pos, head, member); \
195237
pos = list_next_entry(pos, member))
196238

239+
/**
240+
* list_for_each_entry_reverse - iterate backwards over list of given type.
241+
* @pos: the type * to use as a loop cursor.
242+
* @head: the head for your list.
243+
* @member: the name of the list_head within the struct.
244+
*/
245+
#define list_for_each_entry_reverse(pos, head, member) \
246+
for (pos = list_last_entry(head, typeof(*pos), member); \
247+
!list_entry_is_head(pos, head, member); \
248+
pos = list_prev_entry(pos, member))
249+
197250
/**
198251
* list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry
199252
* @pos: the type * to use as a loop cursor.

0 commit comments

Comments
 (0)