linux 内核 list_head 与包含 list_head 的空条目

linux kernel list_head vs empty entry that contains list_head

我试图通过查看 list_for_each_entry 的宏扩展来了解此列表的工作原理,退出 for 的条件是

&pos->list_member != head

但是我看到这样写的代码并且工作正常,我不明白为什么它工作

struct entry {
    int some_var;
    struct list_head list;
};

struct global {
    struct list_head entries_list;
};

struct global Global;
INIT_LIST_HEAD(&global.entries_list)
entry = kmalloc(new_entry..)
list_add_tail(&entry,&Global.entries_list);
list_for_each_entry(entry,&Global.entries_list,list) {

}

那么在 for 结束时,我应该期待 &entry->list == &Global.entries_list? 这怎么可能?

So by the end of the for, I should expect &entry->list == &Global.entries_list?

是的。

How is this possible?

上面的条件意味着entry假的:它不是列表中的一个元素,而只是一个满足给定条件的原始指针。