Reputation: 1129
I'm trying to understand how this list works, by looking at the macro expansion of list_for_each_entry, the condition to exit the for is
&pos->list_member != head
but I see code that written like this and works fine, I don't understand why it works
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) {
}
So by the end of the for, I should expect &entry->list == &Global.entries_list
?
How is this possible?
Upvotes: 0
Views: 528
Reputation: 66298
So by the end of the for, I should expect
&entry->list == &Global.entries_list
?
Yes.
How is this possible?
Condition above means that entry
is fake: it is not an element in the list, but just a raw pointer, which satisfies to given condition.
Upvotes: 1