From 83d1e54bd591e16a6a4529501cbcb2b32a232383 Mon Sep 17 00:00:00 2001 From: Boram Park Date: Fri, 30 Mar 2018 13:04:00 +0900 Subject: [PATCH] add LIST_FIRST_ENTRY, LIST_LAST_ENTRY macro Change-Id: I98adf7df5ecb3dd94627e06bda3eb253033b289d --- include/tdm_list.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/tdm_list.h b/include/tdm_list.h index 7475894..3873817 100644 --- a/include/tdm_list.h +++ b/include/tdm_list.h @@ -112,6 +112,12 @@ static inline int list_length(struct list_head *item) #define LIST_ENTRY(__type, __item, __field) \ ((__type *)(((char *)(__item)) - offsetof(__type, __field))) +#define LIST_FIRST_ENTRY(__ptr, __type, __field) \ + LIST_ENTRY(__type, (__ptr)->next, __field) + +#define LIST_LAST_ENTRY(__ptr, __type, __field) \ + LIST_ENTRY(__type, (__ptr)->prev, __field) + #define LIST_IS_EMPTY(__list) \ ((__list)->next == (__list)) -- 2.7.4