[PATCH 1/3] backports: add list_count_nodes()

Johannes Berg <[email protected]> Fri, 24 May 2024 19:48:16 +0200
Newsgroups org.kernel.vger.backports
Message-ID <20240524194829.f11312298857.I2921f495b9feefbfe464ffd71c7350c66be119a8@changeid>
From: Johannes Berg <[email protected]>

Signed-off-by: Johannes Berg <[email protected]>
---
 backport/backport-include/linux/list.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 backport/backport-include/linux/list.h

diff --git a/backport/backport-include/linux/list.h b/backport/backport-include/linux/list.h
new file mode 100644
index 000000000000..8495fd419a95
--- /dev/null
+++ b/backport/backport-include/linux/list.h
@@ -0,0 +1,19 @@
+#ifndef __BP_LINUX_LIST_H
+#define __BP_LINUX_LIST_H
+#include_next <linux/list.h>
+
+#if LINUX_VERSION_IS_LESS(6,3,0)
+#define list_count_nodes LINUX_BACKPORT(list_count_nodes)
+static inline size_t list_count_nodes(struct list_head *head)
+{
+	struct list_head *pos;
+	size_t count = 0;
+
+	list_for_each(pos, head)
+		count++;
+
+	return count;
+}
+#endif
+
+#endif /* __BP_LINUX_LIST_H */
-- 
2.45.1