list.h

include/linux/list.h

list_add

/** 每次添加节点到head之后,始终都是添加到头结点之后
 * list_add - add a new entry  添加新条目
 * @new: new entry to be added  要添加的新条目
 * @head: list head to add it after 列出要在其后添加的头
 *
 * Insert a new entry after the specified head. 在指定的头部后插入一个新条目
 * This is good for implementing stacks. 这有利于实现堆栈
 */
static inline void list_add(struct list_head *new, struct list_head *head)
{
	__list_add(new, head, head->next);
}

__list_add

/*
 * Insert a new entry between two known consecutive entries.
 * 在两个已知的连续条目之间插入一个新条目
 * This is only for internal list manipulation where we know
 * 这仅用于我们知道的内部列表操作
 * the prev/next entries already!
 * 已经存在的上一个/下一个条目
 */
static inline void __list_add(struct list_head *new,
			      struct list_head *prev,
			      struct list_head *next)
{
	if (!__list_add_valid(new, prev, next))
		return;
    // prev <-> new <-> next
	next->prev = new;
	new->next = next;
	new->prev = prev;
	WRITE_ONCE(prev->next, new);  安全地将prev->next指向new
}
INIT_LIST_HEAD
static inline void INIT_LIST_HEAD(struct list_head *list)
{
	WRITE_ONCE(list->next, list); // 后1个节点指向自己
	list->prev = list; //前一个节点指向自己
}
list_del_init
/** 从列表中删除条目并重新初始化它
 * list_del_init - deletes entry from list and reinitialize it.
 * @entry: the element to delete from the list.
 */
static inline void list_del_init(struct list_head *entry)
{
	__list_del_entry(entry); // 把entry节点删除
	INIT_LIST_HEAD(entry);
}

__list_del_entry

static inline void __list_del_entry(struct list_head *entry)
{
	if (!__list_del_entry_valid(entry))
		return;
	__list_del(entry->prev, entry->next);
}

__list_del

static inline void __list_del(struct list_head * prev, struct list_head * next)
{	// 假设 a <-> b <-> c   现在把b节点删除
	next->prev = prev; //  c.prev =a
	WRITE_ONCE(prev->next, next); // a.next=b
}
types.h

kernel/inclue/linux/types.h

struct list_head {
	struct list_head *next, *prev;
};