diff options
author | Pierre Gondois <pierre.gondois@arm.com> | 2024-01-04 19:49:33 +0300 |
---|---|---|
committer | Andrew Morton <akpm@linux-foundation.org> | 2024-02-23 02:38:51 +0300 |
commit | a43c47561e46cbefc6a2fe2c3f8f6bda0e553a83 (patch) | |
tree | e540b87453459bcb6cc7eff3a08bd7041a4f87b2 /include | |
parent | 7c37857fc23a7e0ff0bf51cc2ea47d9140d1f6a3 (diff) | |
download | linux-a43c47561e46cbefc6a2fe2c3f8f6bda0e553a83.tar.xz |
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/20240104164937.424320-1-pierre.gondois@arm.com
Link: https://lkml.kernel.org/r/20240104164937.424320-2-pierre.gondois@arm.com
Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
Reviewed-by: Carlos Llamas <cmllamas@google.com>
Acked-by: Coly Li <colyli@suse.de>
Acked-by: Marco Elver <elver@google.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Arve Hjønnevåg <arve@android.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Joel Fernandes (Google) <joel@joelfernandes.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Martijn Coenen <maco@android.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Todd Kjos <tkjos@android.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/list.h | 15 |
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 |