From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: torvalds@linux-foundation.org
Cc: arnd@arndb.de, jakobkoschel@gmail.com,
linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org,
keescook@chromium.org, jannh@google.com,
linux-kbuild@vger.kernel.org, linux-mm@kvack.org,
netdev@vger.kernel.org, Xiaomeng Tong <xiam0nd.tong@gmail.com>
Subject: [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop
Date: Tue, 1 Mar 2022 15:58:35 +0800 [thread overview]
Message-ID: <20220301075839.4156-3-xiam0nd.tong@gmail.com> (raw)
In-Reply-To: <20220301075839.4156-1-xiam0nd.tong@gmail.com>
For each list_for_each_entry* macros(10 variants), implements a respective
new *_inside one. Such as the new macro list_for_each_entry_inside for
list_for_each_entry. The idea is to be as compatible with the original
interface as possible and to minimize code changes.
Here are 2 examples:
list_for_each_entry_inside:
- declare the iterator-variable pos inside the loop. Thus, the origin
declare of the inputed *pos* outside the loop should be removed. In
other words, the inputed *pos* now is just a string name.
- add a new "type" argument as the type of the container struct this is
embedded in, and should be inputed when calling the macro.
list_for_each_entry_safe_continue_inside:
- declare the iterator-variable pos and n inside the loop. Thus, the
origin declares of the inputed *pos* and *n* outside the loop should
be removed. In other words, the inputed *pos* and *n* now are just
string name.
- add a new "start" argument as the given iterator to start with and
can be used to get the container struct *type*. This should be inputed
when calling the macro.
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
include/linux/list.h | 156 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 156 insertions(+)
diff --git a/include/linux/list.h b/include/linux/list.h
index dd6c2041d..1595ce865 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -639,6 +639,19 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
+/**
+ * list_for_each_entry_inside
+ * - iterate over list of given type and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @type: the type of the container struct this is embedded in.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_for_each_entry_inside(pos, type, head, member) \
+ for (type * pos = list_first_entry(head, type, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = list_next_entry(pos, member))
+
/**
* list_for_each_entry_reverse - iterate backwards over list of given type.
* @pos: the type * to use as a loop cursor.
@@ -650,6 +663,19 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
+/**
+ * list_for_each_entry_reverse_inside
+ * - iterate backwards over list of given type and keep iterator inside the loop.
+ * @pos: the type * to use as a loop cursor.
+ * @type: the type of the container struct this is embedded in.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_for_each_entry_reverse_inside(pos, type, head, member) \
+ for (type * pos = list_last_entry(head, type, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = list_prev_entry(pos, member))
+
/**
* list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue()
* @pos: the type * to use as a start point
@@ -675,6 +701,22 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
+/**
+ * list_for_each_entry_continue_inside
+ * - continue iteration over list of given type and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Continue to iterate over list of given type, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_inside(pos, start, head, member) \
+ for (typeof(*start) *pos = list_next_entry(start, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = list_next_entry(pos, member))
+
/**
* list_for_each_entry_continue_reverse - iterate backwards from the given point
* @pos: the type * to use as a loop cursor.
@@ -689,6 +731,22 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
+/**
+ * list_for_each_entry_continue_reverse_inside
+ * - iterate backwards from the given point and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Start to iterate over list of given type backwards, continuing after
+ * the current position.
+ */
+#define list_for_each_entry_continue_reverse_inside(pos, start, head, member) \
+ for (typeof(*start) *pos = list_prev_entry(start, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = list_prev_entry(pos, member))
+
/**
* list_for_each_entry_from - iterate over list of given type from the current point
* @pos: the type * to use as a loop cursor.
@@ -701,6 +759,20 @@ static inline void list_splice_tail_init(struct list_head *list,
for (; !list_entry_is_head(pos, head, member); \
pos = list_next_entry(pos, member))
+/**
+ * list_for_each_entry_from_inside
+ * - iterate over list of given type from the current point and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Iterate over list of given type, continuing from current position.
+ */
+#define list_for_each_entry_from_inside(pos, start, head, member) \
+ for (typeof(*start) *pos = start; !list_entry_is_head(pos, head, member); \
+ pos = list_next_entry(pos, member))
+
/**
* list_for_each_entry_from_reverse - iterate backwards over list of given type
* from the current point
@@ -714,6 +786,21 @@ static inline void list_splice_tail_init(struct list_head *list,
for (; !list_entry_is_head(pos, head, member); \
pos = list_prev_entry(pos, member))
+/**
+ * list_for_each_entry_from_reverse_inside
+ * - iterate backwards over list of given type from the current point
+ * and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Iterate backwards over list of given type, continuing from current position.
+ */
+#define list_for_each_entry_from_reverse_inside(pos, start, head, member) \
+ for (typeof(*start) *pos = start; !list_entry_is_head(pos, head, member); \
+ pos = list_prev_entry(pos, member))
+
/**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
* @pos: the type * to use as a loop cursor.
@@ -727,6 +814,22 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
+/**
+ * list_for_each_entry_safe_inside
+ * - iterate over list of given type safe against removal of list entry
+ * and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @type: the type of the container struct this is embedded in.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ */
+#define list_for_each_entry_safe_inside(pos, n, type, head, member) \
+ for (type * pos = list_first_entry(head, type, member), \
+ *n = list_next_entry(pos, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = n, n = list_next_entry(n, member))
+
/**
* list_for_each_entry_safe_continue - continue list iteration safe against removal
* @pos: the type * to use as a loop cursor.
@@ -743,6 +846,24 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
+/**
+ * list_for_each_entry_safe_continue_inside
+ * - continue list iteration safe against removal and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Iterate over list of given type, continuing after current point,
+ * safe against removal of list entry.
+ */
+#define list_for_each_entry_safe_continue_inside(pos, n, start, head, member) \
+ for (typeof(*start) *pos = list_next_entry(start, member), \
+ *n = list_next_entry(pos, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = n, n = list_next_entry(n, member))
+
/**
* list_for_each_entry_safe_from - iterate over list from current point safe against removal
* @pos: the type * to use as a loop cursor.
@@ -758,6 +879,23 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, member))
+/**
+ * list_for_each_entry_safe_from_inside
+ * - iterate over list from current point safe against removal and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @start: the given iterator to start with.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Iterate over list of given type from current point, safe against
+ * removal of list entry.
+ */
+#define list_for_each_entry_safe_from_inside(pos, n, start, head, member) \
+ for (typeof(*start) *pos = start, *n = list_next_entry(pos, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = n, n = list_next_entry(n, member))
+
/**
* list_for_each_entry_safe_reverse - iterate backwards over list safe against removal
* @pos: the type * to use as a loop cursor.
@@ -774,6 +912,24 @@ static inline void list_splice_tail_init(struct list_head *list,
!list_entry_is_head(pos, head, member); \
pos = n, n = list_prev_entry(n, member))
+/**
+ * list_for_each_entry_safe_reverse_insde
+ * - iterate backwards over list safe against removal and keep iterator inside the loop
+ * @pos: the type * to use as a loop cursor.
+ * @n: another type * to use as temporary storage
+ * @type: the type of the struct this is enmbeded in.
+ * @head: the head for your list.
+ * @member: the name of the list_head within the struct.
+ *
+ * Iterate backwards over list of given type, safe against removal
+ * of list entry.
+ */
+#define list_for_each_entry_safe_reverse_inside(pos, n, type, head, member) \
+ for (type * pos = list_last_entry(head, type, member), \
+ *n = list_prev_entry(pos, member); \
+ !list_entry_is_head(pos, head, member); \
+ pos = n, n = list_prev_entry(n, member))
+
/**
* list_safe_reset_next - reset a stale list_for_each_entry_safe loop
* @pos: the loop cursor used in the list_for_each_entry_safe loop
--
2.17.1
next prev parent reply other threads:[~2022-03-01 7:59 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-01 7:58 [PATCH 0/6] list_for_each_entry*: " Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 1/6] Kbuild: compile kernel with gnu11 std Xiaomeng Tong
2022-03-01 17:59 ` kernel test robot
2022-03-01 20:16 ` Linus Torvalds
2022-03-01 20:54 ` Arnd Bergmann
2022-03-01 21:04 ` Linus Torvalds
2022-03-01 21:15 ` Linus Torvalds
2022-03-01 21:43 ` Xiaomeng Tong
2022-03-01 7:58 ` Xiaomeng Tong [this message]
2022-03-02 2:52 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop kernel test robot
2022-03-02 13:02 ` James Bottomley
2022-03-03 3:31 ` Xiaomeng Tong
2022-03-06 14:33 ` James Bottomley
2022-03-03 20:02 ` Linus Torvalds
2022-03-04 2:51 ` Xiaomeng Tong
2022-03-05 21:09 ` Linus Torvalds
2022-03-06 0:35 ` Linus Torvalds
2022-03-06 12:19 ` Jakob Koschel
2022-03-06 18:57 ` Linus Torvalds
2022-03-06 14:06 ` Xiaomeng Tong
2022-03-10 23:54 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable Michał Mirosław
2022-03-11 0:46 ` Linus Torvalds
2022-03-12 10:24 ` Michał Mirosław
2022-03-12 21:43 ` Linus Torvalds
2022-03-11 7:15 ` [RFC PATCH] list: test: Add a test for list_traverse David Gow
2022-03-11 14:27 ` [PATCH 2/6] list: add new MACROs to make iterator invisiable outside the loop Daniel Thompson
2022-03-11 18:41 ` Linus Torvalds
2022-03-16 15:45 ` Daniel Thompson
2022-03-01 7:58 ` [PATCH 3/6] kernel: remove iterator use " Xiaomeng Tong
2022-03-01 10:41 ` Greg KH
2022-03-01 11:34 ` Xiaomeng Tong
2022-03-01 11:48 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 4/6] mm: " Xiaomeng Tong
2022-03-01 12:19 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 5/6] net/core: " Xiaomeng Tong
2022-03-01 12:23 ` Xiaomeng Tong
2022-03-01 7:58 ` [PATCH 6/6] drivers/dma: " Xiaomeng Tong
2022-03-01 12:25 ` Xiaomeng Tong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220301075839.4156-3-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=arnd@arndb.de \
--cc=gregkh@linuxfoundation.org \
--cc=jakobkoschel@gmail.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox