mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 23:10:53 +07:00
introduce kmod_list_last()
This gets the last element in the list, that is, the previous element of the head.
This commit is contained in:
parent
2a70a5d4e0
commit
d5ec60bc0c
@ -310,3 +310,23 @@ KMOD_EXPORT struct kmod_list *kmod_list_next(const struct kmod_list *list,
|
||||
|
||||
return container_of(curr->node.next, struct kmod_list, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* kmod_list_last:
|
||||
* @list: the head of the list
|
||||
*
|
||||
* Get the last element of the @list. As @list is a circular list,
|
||||
* this is a cheap operation O(1) with the last element being the
|
||||
* previous element.
|
||||
*
|
||||
* If the list has a single element it will return the list itself (as
|
||||
* expected, and this is what differentiates from kmod_list_prev()).
|
||||
*
|
||||
* Returns: last node at @list or NULL if the list is empty.
|
||||
*/
|
||||
KMOD_EXPORT struct kmod_list *kmod_list_last(const struct kmod_list *list)
|
||||
{
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
return container_of(list->node.prev, struct kmod_list, node);
|
||||
}
|
||||
|
@ -62,6 +62,8 @@ struct kmod_list *kmod_list_next(const struct kmod_list *first_entry,
|
||||
const struct kmod_list *list_entry);
|
||||
struct kmod_list *kmod_list_prev(const struct kmod_list *first_entry,
|
||||
const struct kmod_list *list_entry);
|
||||
struct kmod_list *kmod_list_last(const struct kmod_list *first_entry);
|
||||
|
||||
#define kmod_list_foreach(list_entry, first_entry) \
|
||||
for (list_entry = first_entry; \
|
||||
list_entry != NULL; \
|
||||
|
@ -11,6 +11,7 @@ global:
|
||||
kmod_unref;
|
||||
kmod_list_next;
|
||||
kmod_list_prev;
|
||||
kmod_list_last;
|
||||
|
||||
kmod_load_resources;
|
||||
kmod_unload_resources;
|
||||
|
Loading…
Reference in New Issue
Block a user