From 041f60ec0df820dcc7afd5440d3f7b4f470ec173 Mon Sep 17 00:00:00 2001 From: Pavel Emelianov Date: Sat, 28 Jun 2008 09:59:54 -0300 Subject: [PATCH] list: Introduce a handy list_first_entry macro From: Pavel Emelianov There are many places where the construction like foo = list_entry(head->next, struct foo_struct, list); are used. The code might look more descriptive and neat if using the macro list_first_entry(head, type, member) \ list_entry((head)->next, type, member) Signed-off-by: Arnaldo Carvalho de Melo --- list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/list.h b/list.h index dff62bc..cac4c89 100644 --- a/list.h +++ b/list.h @@ -280,6 +280,17 @@ static inline void list_splice_init(struct list_head *list, #define list_entry(ptr, type, member) \ container_of(ptr, type, member) +/** + * 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_struct 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) + /** * list_for_each - iterate over a list * @pos: the &struct list_head to use as a loop cursor.