[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250208163959.3973163-4-ole0811sch@gmail.com>
Date: Sat, 8 Feb 2025 17:39:51 +0100
From: Ole Schuerks <ole0811sch@...il.com>
To: linux-kbuild@...r.kernel.org
Cc: ole0811sch@...il.com,
jude.gyimah@....de,
thorsten.berger@....de,
deltaone@...ian.org,
jan.sollmann@....de,
mcgrof@...nel.org,
masahiroy@...nel.org,
linux-kernel@...r.kernel.org,
nathan@...nel.org,
nicolas@...sle.eu
Subject: [PATCH v7 03/11] kbuild: Add list_count_nodes and list_for_each_entry_from
list_count_nodes and list_for_each_entry_from exist in
include/linux/list.h. Add them to scripts/include/list.h.
Signed-off-by: Ole Schuerks <ole0811sch@...il.com>
---
scripts/include/list.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/scripts/include/list.h b/scripts/include/list.h
index 8bdcaadca709..b60f1cc878f1 100644
--- a/scripts/include/list.h
+++ b/scripts/include/list.h
@@ -219,6 +219,20 @@ static inline int list_empty(const struct list_head *head)
return head->next == head;
}
+/**
+ * list_count_nodes - count nodes in the list
+ * @head: the head for your list.
+ */
+static inline size_t list_count_nodes(struct list_head *head)
+{
+ size_t count = 0;
+
+ for (struct list_head *pos = head->next; pos != head; pos = pos->next)
+ ++count;
+
+ return count;
+}
+
/**
* list_entry - get the struct for this entry
* @ptr: the &struct list_head pointer.
@@ -310,6 +324,18 @@ static inline int list_empty(const struct list_head *head)
!list_entry_is_head(pos, head, member); \
pos = n, n = list_next_entry(n, 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.
+ * @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(pos, head, member) \
+ for (; !list_entry_is_head(pos, head, member); \
+ pos = list_next_entry(pos, member))
+
/*
* Double linked lists with a single pointer list head.
* Mostly useful for hash tables where the two pointer list head is
--
2.39.5
Powered by blists - more mailing lists