Hay guys!
I'm changing the kernel code at the Rat Hat OS and I want to use the macro开发者_运维百科 "list entry". I can't find anywhere what is the return value in case of failure..
What will it return if the list is empty? or at any other case...
Thanks!! Ami
It should be something undefined if the list is empty. (You're trying to dereference a list pointer that's not in a struct of the list's element type)
Generally, if you must use list_entry directly, you want to check if list_empty first. This will verify your list head doesn't point to itself.
Otherwise stick to always using the list_for_each macros which will generate a for loop over your elements.
We can use this list_head in two ways
1) independent single global variable, to HOLD the list as head to all
we can not use the list_entry on this variable event though there are list members in it. because this is not part of any structure.
2) we can use list_head as member of the your structure, wile adding to the list you will give this member pointer to the list HEAD.
we will use list_entry on this member to get the your structure even though your list member is not part of any List(it initialized with next=NULL and priv=NULL) you can get structure there is no way to fail.
list_entry is simple container_of() we use this to get the structure pointer using member pointer.
精彩评论