Message ID | 20240730111132.1097315-1-sughosh.ganu@linaro.org |
---|---|
State | New |
Headers | show |
Series | [1/5] linux: list: add a function to count list nodes | expand |
On Tue, 30 Jul 2024 at 05:11, Sughosh Ganu <sughosh.ganu@linaro.org> wrote: > > Add a function to count the nodes of a list. > > Taken from linux 6.11-rc1 tag commit 8400291e289e. > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> > --- > include/linux/list.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) Reviewed-by: Simon Glass <sjg@chromium.org>
On 7/30/24 13:11, Sughosh Ganu wrote: > Add a function to count the nodes of a list. This could function could be used in lot of different code locations: test/boot/expo.c:707 lib/fwu_updates/fwu_mtd.c:64 lib/efi_loader/efi_memory.c:755 lib/efi_loader/efi_boottime.c:2519 fs/yaffs2/yaffs_guts.c:4460 drivers/mtd/ubi/fastmap.c:589 drivers/mtd/ubi/fastmap.c:586 drivers/core/util.c:18 boot/scene.c:85 Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> > > Taken from linux 6.11-rc1 tag commit 8400291e289e. > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> > --- > include/linux/list.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/include/linux/list.h b/include/linux/list.h > index 6910721c00..0f9d939b05 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -547,6 +547,21 @@ static inline void list_splice_tail_init(struct list_head *list, > &pos->member != (head); \ > pos = n, n = list_entry(n->member.prev, typeof(*n), member)) > > +/** > + * list_count_nodes - count nodes in the list > + * @head: the head for your list. > + */ > +static inline size_t list_count_nodes(struct list_head *head) > +{ > + struct list_head *pos; > + size_t count = 0; > + > + list_for_each(pos, head) > + count++; > + > + return count; > +} > + > /* > * Double linked lists with a single pointer list head. > * Mostly useful for hash tables where the two pointer list head is
On Tue, 30 Jul 2024 at 14:11, Sughosh Ganu <sughosh.ganu@linaro.org> wrote: > > Add a function to count the nodes of a list. > > Taken from linux 6.11-rc1 tag commit 8400291e289e. > > Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> > --- > include/linux/list.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/include/linux/list.h b/include/linux/list.h > index 6910721c00..0f9d939b05 100644 > --- a/include/linux/list.h > +++ b/include/linux/list.h > @@ -547,6 +547,21 @@ static inline void list_splice_tail_init(struct list_head *list, > &pos->member != (head); \ > pos = n, n = list_entry(n->member.prev, typeof(*n), member)) > > +/** > + * list_count_nodes - count nodes in the list > + * @head: the head for your list. > + */ > +static inline size_t list_count_nodes(struct list_head *head) > +{ > + struct list_head *pos; > + size_t count = 0; > + > + list_for_each(pos, head) > + count++; > + > + return count; > +} > + > /* > * Double linked lists with a single pointer list head. > * Mostly useful for hash tables where the two pointer list head is > -- > 2.34.1 > Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
diff --git a/include/linux/list.h b/include/linux/list.h index 6910721c00..0f9d939b05 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -547,6 +547,21 @@ static inline void list_splice_tail_init(struct list_head *list, &pos->member != (head); \ pos = n, n = list_entry(n->member.prev, typeof(*n), member)) +/** + * list_count_nodes - count nodes in the list + * @head: the head for your list. + */ +static inline size_t list_count_nodes(struct list_head *head) +{ + struct list_head *pos; + size_t count = 0; + + list_for_each(pos, head) + count++; + + return count; +} + /* * Double linked lists with a single pointer list head. * Mostly useful for hash tables where the two pointer list head is
Add a function to count the nodes of a list. Taken from linux 6.11-rc1 tag commit 8400291e289e. Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org> --- include/linux/list.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)