From nobody Fri Dec 26 13:27:46 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1786525577; Thu, 4 Jan 2024 16:50:32 +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 6A65E1007; Thu, 4 Jan 2024 08:51:18 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.76.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DBA663F64C; Thu, 4 Jan 2024 08:50:28 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Coly Li , Kent Overstreet , Marco Elver , Kees Cook , Jani Nikula , Lucas De Marchi , Ingo Molnar , Andy Shevchenko , linux-bcache@vger.kernel.org Subject: [PATCH v2 1/3] list: Add hlist_count_nodes() Date: Thu, 4 Jan 2024 17:49:33 +0100 Message-Id: <20240104164937.424320-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104164937.424320-1-pierre.gondois@arm.com> References: <20240104164937.424320-1-pierre.gondois@arm.com> 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 Acked-by: Coly Li Acked-by: Marco Elver Reviewed-by: Andy Shevchenko Reviewed-by: Carlos Llamas --- 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 From nobody Fri Dec 26 13:27:46 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5351288D5; Thu, 4 Jan 2024 16:50:39 +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 1BA391007; Thu, 4 Jan 2024 08:51:25 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.76.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 310D83F64C; Thu, 4 Jan 2024 08:50:35 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Coly Li , Kent Overstreet , Marco Elver , Kees Cook , Lucas De Marchi , Ingo Molnar , Andy Shevchenko , linux-bcache@vger.kernel.org Subject: [PATCH v2 2/3] binder: Use of hlist_count_nodes() Date: Thu, 4 Jan 2024 17:49:34 +0100 Message-Id: <20240104164937.424320-3-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104164937.424320-1-pierre.gondois@arm.com> References: <20240104164937.424320-1-pierre.gondois@arm.com> 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" Make use of the newly added hlist_count_nodes(). Signed-off-by: Pierre Gondois Acked-by: Carlos Llamas Acked-by: Marco Elver Reviewed-by: Andy Shevchenko --- drivers/android/binder.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/android/binder.c b/drivers/android/binder.c index 92128aae2d06..f9ca4d58d825 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -6077,9 +6077,7 @@ static void print_binder_node_nilocked(struct seq_fil= e *m, struct binder_work *w; int count; =20 - count =3D 0; - hlist_for_each_entry(ref, &node->refs, node_entry) - count++; + count =3D hlist_count_nodes(&node->refs); =20 seq_printf(m, " node %d: u%016llx c%016llx hs %d hw %d ls %d lw %d is %d= iw %d tr %d", node->debug_id, (u64)node->ptr, (u64)node->cookie, --=20 2.25.1 From nobody Fri Dec 26 13:27:46 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEA8B25569; Thu, 4 Jan 2024 16:50:46 +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 12DDE1007; Thu, 4 Jan 2024 08:51:32 -0800 (PST) Received: from e126645.arm.com (unknown [10.57.76.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 412BC3F64C; Thu, 4 Jan 2024 08:50:42 -0800 (PST) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Greg Kroah-Hartman , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Christian Brauner , Carlos Llamas , Suren Baghdasaryan , Coly Li , Kent Overstreet , Marco Elver , Kees Cook , Lucas De Marchi , Ingo Molnar , Andy Shevchenko , linux-bcache@vger.kernel.org Subject: [PATCH v2 3/3] bcache: Use of hlist_count_nodes() Date: Thu, 4 Jan 2024 17:49:35 +0100 Message-Id: <20240104164937.424320-4-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240104164937.424320-1-pierre.gondois@arm.com> References: <20240104164937.424320-1-pierre.gondois@arm.com> 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" Make use of the newly added hlist_count_nodes(). Signed-off-by: Pierre Gondois Acked-by: Coly Li Acked-by: Marco Elver Reviewed-by: Andy Shevchenko --- drivers/md/bcache/sysfs.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index a438efb66069..6956beb55326 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -702,13 +702,7 @@ static unsigned int bch_cache_max_chain(struct cache_s= et *c) for (h =3D c->bucket_hash; h < c->bucket_hash + (1 << BUCKET_HASH_BITS); h++) { - unsigned int i =3D 0; - struct hlist_node *p; - - hlist_for_each(p, h) - i++; - - ret =3D max(ret, i); + ret =3D max(ret, hlist_count_nodes(h)); } =20 mutex_unlock(&c->bucket_lock); --=20 2.25.1