From 91001a992336e582b9e518e74e673d255ded986b Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Thu, 3 Sep 2020 20:22:42 -0700 Subject: [PATCH] include: implement list_empty() and list_for_each_entry() Implement list_empty() function and list_for_each_entry() macro, newly used by xsk.c in 2f6324a3937f ("libbpf: Support shared umems between queues and devices") (Linux commit sha). Fixes: 5f630710f52e ("libbpf: Support shared umems between queues and devices") Signed-off-by: Andrii Nakryiko --- include/linux/list.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index e3814f7..fc91c34 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -72,11 +72,20 @@ static inline void list_del(struct list_head *entry) entry->prev = LIST_POISON2; } +static inline int list_empty(const struct list_head *head) +{ + return head->next == head; +} + #define list_entry(ptr, type, member) \ container_of(ptr, type, member) #define list_first_entry(ptr, type, member) \ list_entry((ptr)->next, type, member) #define list_next_entry(pos, member) \ list_entry((pos)->member.next, typeof(*(pos)), member) +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + &pos->member != (head); \ + pos = list_next_entry(pos, member)) #endif