linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/4] list: Introduce list_count() to count existing nodes
@ 2022-11-14 11:28 Andy Shevchenko
  2022-11-14 11:28 ` [PATCH v1 2/4] usb: gadget: hid: Convert to use list_count() Andy Shevchenko
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Andy Shevchenko @ 2022-11-14 11:28 UTC (permalink / raw)
  To: Jakob Koschel, Andy Shevchenko, Greg Kroah-Hartman, Mathias Nyman,
	linux-usb, linux-kernel
  Cc: Kevin Cernekee, Mathias Nyman, Andrew Morton

Some of the existing users, and definitely will be new ones, want to
count existing nodes in the list. Provide a generic API for that.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/list.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index 61762054b4be..098eccf8c1b6 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -655,6 +655,19 @@ static inline void list_splice_tail_init(struct list_head *list,
 	     !list_is_head(pos, (head)); \
 	     pos = n, n = pos->prev)
 
+/**
+ * list_count - count nodes in the list
+ * @head:	the head for your list.
+ */
+#define list_count(head)		\
+({					\
+	struct list_head *__tmp;	\
+	size_t __i = 0;			\
+	list_for_each(__tmp, head)	\
+		__i++;			\
+	__i;				\
+})
+
 /**
  * list_entry_is_head - test if the entry points to the head of the list
  * @pos:	the type * to cursor
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-14 18:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-14 11:28 [PATCH v1 1/4] list: Introduce list_count() to count existing nodes Andy Shevchenko
2022-11-14 11:28 ` [PATCH v1 2/4] usb: gadget: hid: Convert to use list_count() Andy Shevchenko
2022-11-14 11:28 ` [PATCH v1 3/4] usb: gadget: udc: bcm63xx: " Andy Shevchenko
2022-11-14 11:28 ` [PATCH v1 4/4] xhci: " Andy Shevchenko
2022-11-14 15:38 ` [PATCH v1 1/4] list: Introduce list_count() to count existing nodes kernel test robot
2022-11-14 16:03   ` Andy Shevchenko
2022-11-14 17:47     ` Matthew Wilcox
2022-11-14 17:57       ` Andy Shevchenko
2022-11-14 15:38 ` kernel test robot
2022-11-14 18:39 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).