All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Gondois <pierre.gondois@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Pierre Gondois <pierre.gondois@arm.com>,
	Marco Elver <elver@google.com>, Kees Cook <keescook@chromium.org>,
	Lucas De Marchi <lucas.demarchi@intel.com>,
	Jani Nikula <jani.nikula@intel.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Ingo Molnar <mingo@kernel.org>
Subject: [PATCH] list: Add hlist_count_nodes()
Date: Wed,  3 Jan 2024 10:02:38 +0100	[thread overview]
Message-ID: <20240103090241.164817-1-pierre.gondois@arm.com> (raw)

Add a function to count nodes in a hlist. hlist_count_nodes()
is similar to list_count_nodes().

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
---
 include/linux/list.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/list.h b/include/linux/list.h
index 1837caedf723..0f1b1d4a2e2e 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -1175,4 +1175,19 @@ static inline void hlist_move_list(struct hlist_head *old,
 	     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
-- 
2.25.1


             reply	other threads:[~2024-01-03  9:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-03  9:02 Pierre Gondois [this message]
2024-01-03 11:25 ` [PATCH] list: Add hlist_count_nodes() Marco Elver
2024-01-03 12:04   ` Pierre Gondois
2024-01-03 13:46     ` Marco Elver
2024-01-06 14:18       ` Andy Shevchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240103090241.164817-1-pierre.gondois@arm.com \
    --to=pierre.gondois@arm.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=elver@google.com \
    --cc=jani.nikula@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucas.demarchi@intel.com \
    --cc=mingo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.