[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YiqPmIdZ/RGiaOei@qmqm.qmqm.pl>
Date: Fri, 11 Mar 2022 00:54:00 +0100
From: Michał Mirosław <mirq-linux@...e.qmqm.pl>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Xiaomeng Tong <xiam0nd.tong@...il.com>,
Arnd Bergmann <arnd@...db.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jakob Koschel <jakobkoschel@...il.com>,
Jann Horn <jannh@...gle.com>,
Kees Cook <keescook@...omium.org>,
Linux Kbuild mailing list <linux-kbuild@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux-MM <linux-mm@...ck.org>, Netdev <netdev@...r.kernel.org>
Subject: Re: [PATCH 2/6] list: add new MACROs to make iterator invisiable
Hi Linus,
If the macro implementation doesn't have to be pretty, maybe it could go
a step further and remember the list_head's offset? That would look
something like following (expanding on your patch; not compile tested):
#define list_traversal_head(type,name,target_member) \
union { \
struct list_head name; \
type *name##_traversal_type; \
char (*name##_list_head_offset)[offsetof(type, target_member)]; \
}
#define list_traversal_entry(ptr, head) \
(typeof(*head##_traversal_type))((void *)ptr - sizeof(**head##_list_head_offset))
#define list_traversal_entry_head(ptr, head) \
(struct list_head *)((void *)ptr + sizeof(**head##_list_head_offset))
#define list_traversal_entry_is_head(ptr, head) \
(list_traversal_entry_head(ptr, head) == (head))
#define list_traversal_next_entry(ptr, head) \
list_traversal_entry(list_traversal_entry_head(ptr, head)->next)
#define list_traverse(pos, head) \
for (typeof(*head##_traversal_type) pos = list_traversal_entry((head)->next); \
!list_traversal_entry_head(pos, head) == (head); \
pos = list_traversal_next_entry(pos, head))
[Sorry for lack of citations - I found the thread via https://lwn.net/Articles/887097/]
--
Michał Mirosław
Powered by blists - more mailing lists