| 1 |
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ |
| 2 |
|
| 3 |
#ifndef __LINUX_LIST_H |
| 4 |
#define __LINUX_LIST_H |
| 5 |
|
| 6 |
#define LIST_HEAD_INIT(name) { &(name), &(name) } |
| 7 |
#define LIST_HEAD(name) \ |
| 8 |
struct list_head name = LIST_HEAD_INIT(name) |
| 9 |
|
| 10 |
#define POISON_POINTER_DELTA 0 |
| 11 |
#define LIST_POISON1 ((void *) 0x100 + POISON_POINTER_DELTA) |
| 12 |
#define LIST_POISON2 ((void *) 0x200 + POISON_POINTER_DELTA) |
| 13 |
|
| 14 |
|
| 15 |
static inline void INIT_LIST_HEAD(struct list_head *list) |
| 16 |
{ |
| 17 |
list->next = list; |
| 18 |
list->prev = list; |
| 19 |
} |
| 20 |
|
| 21 |
static inline void __list_add(struct list_head *new, |
| 22 |
struct list_head *prev, |
| 23 |
struct list_head *next) |
| 24 |
{ |
| 25 |
next->prev = new; |
| 26 |
new->next = next; |
| 27 |
new->prev = prev; |
| 28 |
prev->next = new; |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* list_add - add a new entry |
| 33 |
* @new: new entry to be added |
| 34 |
* @head: list head to add it after |
| 35 |
* |
| 36 |
* Insert a new entry after the specified head. |
| 37 |
* This is good for implementing stacks. |
| 38 |
*/ |
| 39 |
static inline void list_add(struct list_head *new, struct list_head *head) |
| 40 |
{ |
| 41 |
__list_add(new, head, head->next); |
| 42 |
} |
| 43 |
|
| 44 |
/* |
| 45 |
* Delete a list entry by making the prev/next entries |
| 46 |
* point to each other. |
| 47 |
* |
| 48 |
* This is only for internal list manipulation where we know |
| 49 |
* the prev/next entries already! |
| 50 |
*/ |
| 51 |
static inline void __list_del(struct list_head * prev, struct list_head * next) |
| 52 |
{ |
| 53 |
next->prev = prev; |
| 54 |
prev->next = next; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* list_del - deletes entry from list. |
| 59 |
* @entry: the element to delete from the list. |
| 60 |
* Note: list_empty() on entry does not return true after this, the entry is |
| 61 |
* in an undefined state. |
| 62 |
*/ |
| 63 |
static inline void __list_del_entry(struct list_head *entry) |
| 64 |
{ |
| 65 |
__list_del(entry->prev, entry->next); |
| 66 |
} |
| 67 |
|
| 68 |
static inline void list_del(struct list_head *entry) |
| 69 |
{ |
| 70 |
__list_del(entry->prev, entry->next); |
| 71 |
entry->next = LIST_POISON1; |
| 72 |
entry->prev = LIST_POISON2; |
| 73 |
} |
| 74 |
|
| 75 |
static inline int list_empty(const struct list_head *head) |
| 76 |
{ |
| 77 |
return head->next == head; |
| 78 |
} |
| 79 |
|
| 80 |
#define list_entry(ptr, type, member) \ |
| 81 |
container_of(ptr, type, member) |
| 82 |
#define list_first_entry(ptr, type, member) \ |
| 83 |
list_entry((ptr)->next, type, member) |
| 84 |
#define list_next_entry(pos, member) \ |
| 85 |
list_entry((pos)->member.next, typeof(*(pos)), member) |
| 86 |
#define list_for_each_entry(pos, head, member) \ |
| 87 |
for (pos = list_first_entry(head, typeof(*pos), member); \ |
| 88 |
&pos->member != (head); \ |
| 89 |
pos = list_next_entry(pos, member)) |
| 90 |
|
| 91 |
#endif |