git: 1b18fb7faa75 - main - LinuxKPI: list.h add list_count_nodes()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Wed, 28 Jun 2023 01:33:07 UTC
The branch main has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=1b18fb7faa75cc6dfa2e253190b41e63a997ca9d

commit 1b18fb7faa75cc6dfa2e253190b41e63a997ca9d
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2023-06-26 08:45:17 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2023-06-28 01:32:29 +0000

    LinuxKPI: list.h add list_count_nodes()
    
    Implement list_count_nodes() using a simple loop.  This is needed by
    an updated wireless driver.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      10 days
    Reviewed by:    emaste
    Differential Revision: https://reviews.freebsd.org/D40757
---
 sys/compat/linuxkpi/common/include/linux/list.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/linux/list.h b/sys/compat/linuxkpi/common/include/linux/list.h
index 46da7cc7bc8e..194f09f0c570 100644
--- a/sys/compat/linuxkpi/common/include/linux/list.h
+++ b/sys/compat/linuxkpi/common/include/linux/list.h
@@ -466,6 +466,20 @@ static inline int list_is_last(const struct list_head *list,
 	return list->next == head;
 }
 
+static inline size_t
+list_count_nodes(const struct list_head *list)
+{
+	const struct list_head *lh;
+	size_t count;
+
+	count = 0;
+	list_for_each(lh, list) {
+		count++;
+	}
+
+	return (count);
+}
+
 #define	hlist_entry(ptr, type, field)	container_of(ptr, type, field)
 
 #define	hlist_for_each(p, head)						\