From nobody Fri Dec 26 19:35:24 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6617D182A9 for ; Wed, 3 Jan 2024 09:02:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 91A63C15; Wed, 3 Jan 2024 01:03:41 -0800 (PST) Received: from e126645.nice.arm.com (e126645.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 58FC83F7A6; Wed, 3 Jan 2024 01:02:54 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Marco Elver , Kees Cook , Lucas De Marchi , Jani Nikula , Andy Shevchenko , Ingo Molnar Subject: [PATCH] list: Add hlist_count_nodes() Date: Wed, 3 Jan 2024 10:02:38 +0100 Message-Id: <20240103090241.164817-1-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a function to count nodes in a hlist. hlist_count_nodes() is similar to list_count_nodes(). Signed-off-by: Pierre Gondois --- 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 =3D pos->member.next; 1; }); \ pos =3D hlist_entry_safe(n, typeof(*pos), member)) =20 +/** + * 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 =3D 0; + + hlist_for_each(pos, head) + count++; + + return count; +} + #endif --=20 2.25.1