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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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





[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux