[PATCH 14/20] headers: add list_count_nodes() backport for kernels < 6.5
Yi Cong <[email protected]> Wed, 24 Jun 2026 15:38:38 +0800
| Newsgroups | org.kernel.vger.backports |
|---|---|
| Message-ID | <[email protected]> |
From: Yi Cong <[email protected]> list_count_nodes() was introduced in v6.5 to count the number of nodes in a struct list_head. Provide an inline backport using list_for_each() for older kernels. Signed-off-by: Yi Cong <[email protected]> --- backport/backport-include/linux/list.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 backport/backport-include/linux/list.h diff --git a/backport/backport-include/linux/list.h b/backport/backport-include/linux/list.h new file mode 100644 index 00000000..47d8d24f --- /dev/null +++ b/backport/backport-include/linux/list.h @@ -0,0 +1,25 @@ +#ifndef __BACKPORT_LINUX_LIST_H +#define __BACKPORT_LINUX_LIST_H +#include_next <linux/list.h> +#include <linux/version.h> + +#if LINUX_VERSION_IS_LESS(6,5,0) +/** + * list_count_nodes - count nodes in the list + * @head: the head for your list. + * + * Introduced in v6.5. Provide a backport for older kernels. + */ +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; +} +#endif + +#endif /* __BACKPORT_LINUX_LIST_H */ -- 2.43.0