aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Gondois <[email protected]>2024-01-04 17:49:33 +0100
committerAndrew Morton <[email protected]>2024-02-22 15:38:51 -0800
commita43c47561e46cbefc6a2fe2c3f8f6bda0e553a83 (patch)
treee540b87453459bcb6cc7eff3a08bd7041a4f87b2
parent7c37857fc23a7e0ff0bf51cc2ea47d9140d1f6a3 (diff)
list: add hlist_count_nodes()
Add a generic hlist_count_nodes() function and use it in two drivers. This patch (of 3): Add a function to count nodes in a hlist. hlist_count_nodes() is similar to list_count_nodes(). Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Pierre Gondois <[email protected]> Reviewed-by: Carlos Llamas <[email protected]> Acked-by: Coly Li <[email protected]> Acked-by: Marco Elver <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: Arve Hjønnevåg <[email protected]> Cc: Christian Brauner <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jani Nikula <[email protected]> Cc: Joel Fernandes (Google) <[email protected]> Cc: Kees Cook <[email protected]> Cc: Kent Overstreet <[email protected]> Cc: Martijn Coenen <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Todd Kjos <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
-rw-r--r--include/linux/list.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/list.h b/include/linux/list.h
index 059aa1fff41e..523b7c4d000a 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -1195,4 +1195,19 @@ static inline void hlist_splice_init(struct hlist_head *from,
pos && ({ n = pos->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*pos), member))
+/**
+ * hlist_count_nodes - count nodes in the hlist
+ * @head: the head for your hlist.
+ */
+static inline size_t hlist_count_nodes(struct hlist_head *head)
+{
+ struct hlist_node *pos;
+ size_t count = 0;
+
+ hlist_for_each(pos, head)
+ count++;
+
+ return count;
+}
+
#endif