diff mbox series

[v7,03/11] kbuild: Add list_count_nodes and list_for_each_entry_from

Message ID 20250208163959.3973163-4-ole0811sch@gmail.com (mailing list archive)
State New
Headers show
Series kconfig: Add support for conflict resolution | expand

Commit Message

Ole Schuerks Feb. 8, 2025, 4:39 p.m. UTC
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@gmail.com>
---
 scripts/include/list.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Luis Chamberlain Feb. 10, 2025, 3:36 p.m. UTC | #1
On Sat, Feb 08, 2025 at 05:39:51PM +0100, Ole Schuerks wrote:
> 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@gmail.com>

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>

  Luis
diff mbox series

Patch

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