2024-01-04 16:50:36

by Pierre Gondois

[permalink] [raw]
Subject: [PATCH v2 0/3] list: Add hlist_count_nodes()

v2:
- Add usages of the function to avoid considering it as dead code.
v1:
- https://lore.kernel.org/all/[email protected]/

Add a generic hlist_count_nodes() function.

This function aims to be used in a private module. As suggested by
Marco, having it used would avoid to consider it as dead code.
Thus, add some usages of the function in two drivers.

Pierre Gondois (3):
list: Add hlist_count_nodes()
binder: Use of hlist_count_nodes()
bcache: Use of hlist_count_nodes()

drivers/android/binder.c | 4 +---
drivers/md/bcache/sysfs.c | 8 +-------
include/linux/list.h | 15 +++++++++++++++
3 files changed, 17 insertions(+), 10 deletions(-)

--
2.25.1



2024-01-04 16:51:01

by Pierre Gondois

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

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

Signed-off-by: Pierre Gondois <[email protected]>
---
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


2024-01-04 16:51:21

by Pierre Gondois

[permalink] [raw]
Subject: [PATCH v2 2/3] binder: Use of hlist_count_nodes()

Make use of the newly added hlist_count_nodes().

Signed-off-by: Pierre Gondois <[email protected]>
---
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_file *m,
struct binder_work *w;
int count;

- count = 0;
- hlist_for_each_entry(ref, &node->refs, node_entry)
- count++;
+ count = hlist_count_nodes(&node->refs);

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


2024-01-04 16:51:23

by Pierre Gondois

[permalink] [raw]
Subject: [PATCH v2 3/3] bcache: Use of hlist_count_nodes()

Make use of the newly added hlist_count_nodes().

Signed-off-by: Pierre Gondois <[email protected]>
---
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_set *c)
for (h = c->bucket_hash;
h < c->bucket_hash + (1 << BUCKET_HASH_BITS);
h++) {
- unsigned int i = 0;
- struct hlist_node *p;
-
- hlist_for_each(p, h)
- i++;
-
- ret = max(ret, i);
+ ret = max(ret, hlist_count_nodes(h));
}

mutex_unlock(&c->bucket_lock);
--
2.25.1


2024-01-04 17:23:11

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] list: Add hlist_count_nodes()

On Thu, 4 Jan 2024 at 17:50, Pierre Gondois <[email protected]> wrote:
>
> v2:
> - Add usages of the function to avoid considering it as dead code.
> v1:
> - https://lore.kernel.org/all/[email protected]/
>
> Add a generic hlist_count_nodes() function.
>
> This function aims to be used in a private module. As suggested by
> Marco, having it used would avoid to consider it as dead code.
> Thus, add some usages of the function in two drivers.

Whether or not it's used in a private module is probably irrelevant
from an upstream perspective.

But this is a reasonable cleanup, and at the same time adds API
symmetry with the already existing list_count_nodes().

> Pierre Gondois (3):
> list: Add hlist_count_nodes()
> binder: Use of hlist_count_nodes()
> bcache: Use of hlist_count_nodes()
>
> drivers/android/binder.c | 4 +---
> drivers/md/bcache/sysfs.c | 8 +-------
> include/linux/list.h | 15 +++++++++++++++
> 3 files changed, 17 insertions(+), 10 deletions(-)

For the series:

Acked-by: Marco Elver <[email protected]>

Thanks.

2024-01-04 17:30:23

by Carlos Llamas

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] list: Add hlist_count_nodes()

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 <[email protected]>
> ---
> 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 <[email protected]>

2024-01-04 17:32:00

by Carlos Llamas

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] binder: Use of hlist_count_nodes()

On Thu, Jan 04, 2024 at 05:49:34PM +0100, Pierre Gondois wrote:
> Make use of the newly added hlist_count_nodes().
>
> Signed-off-by: Pierre Gondois <[email protected]>
> ---
> 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_file *m,
> struct binder_work *w;
> int count;
>
> - count = 0;
> - hlist_for_each_entry(ref, &node->refs, node_entry)
> - count++;
> + count = hlist_count_nodes(&node->refs);
>
> 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,
> --
> 2.25.1
>

Looks good to me!

Acked-by: Carlos Llamas <[email protected]>

2024-01-05 06:54:20

by Coly Li

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] list: Add hlist_count_nodes()

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 <[email protected]>

Acked-by: Coly Li <[email protected]>

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

2024-01-05 06:55:44

by Coly Li

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] bcache: Use of hlist_count_nodes()

On Thu, Jan 04, 2024 at 05:49:35PM +0100, Pierre Gondois wrote:
> Make use of the newly added hlist_count_nodes().
>
> Signed-off-by: Pierre Gondois <[email protected]>

Acked-by: Coly Li <[email protected]>

Thanks.

> ---
> 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_set *c)
> for (h = c->bucket_hash;
> h < c->bucket_hash + (1 << BUCKET_HASH_BITS);
> h++) {
> - unsigned int i = 0;
> - struct hlist_node *p;
> -
> - hlist_for_each(p, h)
> - i++;
> -
> - ret = max(ret, i);
> + ret = max(ret, hlist_count_nodes(h));
> }
>
> mutex_unlock(&c->bucket_lock);
> --
> 2.25.1
>
>

--
Coly Li

2024-01-06 14:36:51

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] bcache: Use of hlist_count_nodes()

On Thu, Jan 04, 2024 at 05:49:35PM +0100, Pierre Gondois wrote:
> Make use of the newly added hlist_count_nodes().

...

> for (h = c->bucket_hash;
> h < c->bucket_hash + (1 << BUCKET_HASH_BITS);
> h++) {
> - unsigned int i = 0;
> - struct hlist_node *p;
> -
> - hlist_for_each(p, h)
> - i++;
> -
> - ret = max(ret, i);
> + ret = max(ret, hlist_count_nodes(h));
> }

After this you probably may drop {}.


--
With Best Regards,
Andy Shevchenko



2024-01-06 15:00:36

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] list: Add hlist_count_nodes()

On Thu, Jan 04, 2024 at 05:49:32PM +0100, Pierre Gondois wrote:
> v2:
> - Add usages of the function to avoid considering it as dead code.
> v1:
> - https://lore.kernel.org/all/[email protected]/
>
> Add a generic hlist_count_nodes() function.
>
> This function aims to be used in a private module. As suggested by
> Marco, having it used would avoid to consider it as dead code.
> Thus, add some usages of the function in two drivers.

With or without a nit-pick being addressed,
Reviewed-by: Andy Shevchenko <[email protected]>

--
With Best Regards,
Andy Shevchenko



2024-01-08 07:01:16

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH v2 0/3] list: Add hlist_count_nodes()

On Thu, 4 Jan 2024 at 18:16, Marco Elver <[email protected]> wrote:
> On Thu, 4 Jan 2024 at 17:50, Pierre Gondois <[email protected]> wrote:
> >
> > v2:
> > - Add usages of the function to avoid considering it as dead code.
> > v1:
> > - https://lore.kernel.org/all/[email protected]/
> >
> > Add a generic hlist_count_nodes() function.
> >
> > This function aims to be used in a private module. As suggested by
> > Marco, having it used would avoid to consider it as dead code.
> > Thus, add some usages of the function in two drivers.
>
> Whether or not it's used in a private module is probably irrelevant
> from an upstream perspective.
>
> But this is a reasonable cleanup, and at the same time adds API
> symmetry with the already existing list_count_nodes().
>
> > Pierre Gondois (3):
> > list: Add hlist_count_nodes()
> > binder: Use of hlist_count_nodes()
> > bcache: Use of hlist_count_nodes()
> >
> > drivers/android/binder.c | 4 +---
> > drivers/md/bcache/sysfs.c | 8 +-------
> > include/linux/list.h | 15 +++++++++++++++
> > 3 files changed, 17 insertions(+), 10 deletions(-)
>
> For the series:
>
> Acked-by: Marco Elver <[email protected]>

Btw, there doesn't appear to be a clear maintainer or tree for
include/linux/list.h. Since there have been several Acks/Reviews by
now, did you have a particular tree in mind?
Perhaps Andrew (+Cc) can help.

Thanks,
-- Marco