include/linux/list.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/list.h b/include/linux/list.h index feb773c76ee0..495566be02e1 100644 --- a/include/linux/list.h +++ b/include/linux/list.h @@ -190,6 +190,20 @@ static inline int list_empty(const struct list_head *head) } /** + * list_count - count number of entries on list + * @head: the list to count. + */ +static inline int list_count(const struct list_head *head) +{ + int len = 0; + const struct list_head *p = head; + + while ((p = p->next) != head) + len++; + return len; +} + +/** * list_empty_careful - tests whether a list is empty and not being modified * @head: the list to test * @@ -611,6 +625,20 @@ static inline int hlist_empty(const struct hlist_head *h) return !h->first; } +/** + * hlist_count - count number of entries on hlist + * @head: the list to count. + */ +static inline int hlist_count(const struct hlist_head *head) +{ + int len = 0; + const struct hlist_node *p; + + for (p = head->first; p; p = p->next) + len++; + return len; +} + static inline void __hlist_del(struct hlist_node *n) { struct hlist_node *next = n->next;