[PATCH v2 1/3] list: Add hlist_count_nodes()

Pierre Gondois posted 3 patches 1 year, 11 months ago
[PATCH v2 1/3] list: Add hlist_count_nodes()
Posted by Pierre Gondois 1 year, 11 months ago
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
Re: [PATCH v2 1/3] list: Add hlist_count_nodes()
Posted by Coly Li 1 year, 11 months ago
On Thu, Jan 04, 2024 at 05:49:33PM +0100, Pierre Gondois wrote:
> 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>

Acked-by: Coly Li <colyli@suse.de>

Thanks.

> ---
>  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
> 
> 

-- 
Coly Li
Re: [PATCH v2 1/3] list: Add hlist_count_nodes()
Posted by Carlos Llamas 1 year, 11 months ago
On Thu, Jan 04, 2024 at 05:49:33PM +0100, Pierre Gondois wrote:
> 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
> 

Looks good.

Reviewed-by: Carlos Llamas <cmllamas@google.com>