* [PATCH] list: Add hlist_count_nodes()
@ 2024-01-03 9:02 Pierre Gondois
2024-01-03 11:25 ` Marco Elver
0 siblings, 1 reply; 5+ messages in thread
From: Pierre Gondois @ 2024-01-03 9:02 UTC (permalink / raw)
To: linux-kernel
Cc: Pierre Gondois, Marco Elver, Kees Cook, Lucas De Marchi,
Jani Nikula, Andy Shevchenko, Ingo Molnar
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] list: Add hlist_count_nodes()
2024-01-03 9:02 [PATCH] list: Add hlist_count_nodes() Pierre Gondois
@ 2024-01-03 11:25 ` Marco Elver
2024-01-03 12:04 ` Pierre Gondois
0 siblings, 1 reply; 5+ messages in thread
From: Marco Elver @ 2024-01-03 11:25 UTC (permalink / raw)
To: Pierre Gondois
Cc: linux-kernel, Kees Cook, Lucas De Marchi, Jani Nikula,
Andy Shevchenko, Ingo Molnar
On Wed, 3 Jan 2024 at 10:02, Pierre Gondois <pierre.gondois@arm.com> 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>
Is this patch part of another patch series? As-is, this will be dead
code, and there's no guarantee someone will just go and delete it in
future. Although this function looks useful, we also should avoid
adding new dead code.
> ---
> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] list: Add hlist_count_nodes()
2024-01-03 11:25 ` Marco Elver
@ 2024-01-03 12:04 ` Pierre Gondois
2024-01-03 13:46 ` Marco Elver
0 siblings, 1 reply; 5+ messages in thread
From: Pierre Gondois @ 2024-01-03 12:04 UTC (permalink / raw)
To: Marco Elver
Cc: linux-kernel, Kees Cook, Lucas De Marchi, Jani Nikula,
Andy Shevchenko, Ingo Molnar
Hello Marco,
On 1/3/24 12:25, Marco Elver wrote:
> On Wed, 3 Jan 2024 at 10:02, Pierre Gondois <pierre.gondois@arm.com> 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>
>
> Is this patch part of another patch series? As-is, this will be dead
> code, and there's no guarantee someone will just go and delete it in
> future. Although this function looks useful, we also should avoid
> adding new dead code.
The function is indeed not used in the project right now. I needed
it for a private module. If it helps integrating the function and
not make it dead code, maybe I could add usages at the following
places:
- drivers/gpu/drm/drm_hashtab.c::print_binder_node_nilocked()
- drivers/md/bcache/sysfs.c::bch_cache_max_chain()
Regards,
Pierre
>
>> ---
>> 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
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] list: Add hlist_count_nodes()
2024-01-03 12:04 ` Pierre Gondois
@ 2024-01-03 13:46 ` Marco Elver
2024-01-06 14:18 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Marco Elver @ 2024-01-03 13:46 UTC (permalink / raw)
To: Pierre Gondois
Cc: linux-kernel, Kees Cook, Lucas De Marchi, Jani Nikula,
Andy Shevchenko, Ingo Molnar
On Wed, 3 Jan 2024 at 13:04, Pierre Gondois <pierre.gondois@arm.com> wrote:
>
> Hello Marco,
>
> On 1/3/24 12:25, Marco Elver wrote:
> > On Wed, 3 Jan 2024 at 10:02, Pierre Gondois <pierre.gondois@arm.com> 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>
> >
> > Is this patch part of another patch series? As-is, this will be dead
> > code, and there's no guarantee someone will just go and delete it in
> > future. Although this function looks useful, we also should avoid
> > adding new dead code.
>
> The function is indeed not used in the project right now. I needed
> it for a private module. If it helps integrating the function and
> not make it dead code, maybe I could add usages at the following
> places:
> - drivers/gpu/drm/drm_hashtab.c::print_binder_node_nilocked()
> - drivers/md/bcache/sysfs.c::bch_cache_max_chain()
If this function allows to simplify these other places, by all means
go ahead. That would look a lot better than having an unused function.
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] list: Add hlist_count_nodes()
2024-01-03 13:46 ` Marco Elver
@ 2024-01-06 14:18 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-01-06 14:18 UTC (permalink / raw)
To: Marco Elver
Cc: Pierre Gondois, linux-kernel, Kees Cook, Lucas De Marchi,
Jani Nikula, Ingo Molnar
On Wed, Jan 03, 2024 at 02:46:00PM +0100, Marco Elver wrote:
> On Wed, 3 Jan 2024 at 13:04, Pierre Gondois <pierre.gondois@arm.com> wrote:
> > On 1/3/24 12:25, Marco Elver wrote:
> > > On Wed, 3 Jan 2024 at 10:02, Pierre Gondois <pierre.gondois@arm.com> 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>
> > >
> > > Is this patch part of another patch series? As-is, this will be dead
> > > code, and there's no guarantee someone will just go and delete it in
> > > future. Although this function looks useful, we also should avoid
> > > adding new dead code.
> >
> > The function is indeed not used in the project right now. I needed
> > it for a private module. If it helps integrating the function and
> > not make it dead code, maybe I could add usages at the following
> > places:
> > - drivers/gpu/drm/drm_hashtab.c::print_binder_node_nilocked()
> > - drivers/md/bcache/sysfs.c::bch_cache_max_chain()
>
> If this function allows to simplify these other places, by all means
> go ahead. That would look a lot better than having an unused function.
+1, produce a little series with those drivers being cleaned up.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-06 14:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 9:02 [PATCH] list: Add hlist_count_nodes() Pierre Gondois
2024-01-03 11:25 ` Marco Elver
2024-01-03 12:04 ` Pierre Gondois
2024-01-03 13:46 ` Marco Elver
2024-01-06 14:18 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®