リストの先頭を指す専用の struct list_head がある? もしくは list_head は最後と最初が繋がっている循環リストなので、リストの最後の要素が分かっていても使えるかもしれない。
struct some { int data_foo; struct list_head list; int data_bar; }; struct some some_list[N]; ... /* リストの先頭の要素が持ってる struct list_head */ struct list_head *some_list_first = &some_list[0].list; /* リストの先頭の要素を指すためだけの struct list_head */ struct list_head some_list_head; some_list_head.next = some_list_first; ... struct some *some_first = list_first_entry(&some_list_head, struct some, list);
/** * list_first_entry - get the first element from a list * @ptr: the list head to take the element from. * @type: the type of the struct this is embedded in. * @member: the name of the list_head within the struct. * * Note, that list is expected to be not empty. */ #define list_first_entry(ptr, type, member) \ list_entry((ptr)->next, type, member)