diff --git a/src/commonlib/include/commonlib/list.h b/src/commonlib/include/commonlib/list.h index 9bad52f3a3..ce74ca34b6 100644 --- a/src/commonlib/include/commonlib/list.h +++ b/src/commonlib/include/commonlib/list.h @@ -29,27 +29,27 @@ static inline bool list_is_empty(const struct list_node *head) } // Get next node. -static inline const struct list_node *list_next(const struct list_node *node, - const struct list_node *head) +static inline struct list_node *list_next(const struct list_node *node, + const struct list_node *head) { return node->next; }; // Get prev node. -static inline const struct list_node *list_prev(const struct list_node *node, - const struct list_node *head) +static inline struct list_node *list_prev(const struct list_node *node, + const struct list_node *head) { return node->prev == head ? NULL : node->prev; }; // Get first node. -static inline const struct list_node *list_first(const struct list_node *head) +static inline struct list_node *list_first(const struct list_node *head) { return list_is_empty(head) ? NULL : head->next; } // Get last node. -const struct list_node *list_last(const struct list_node *head); +struct list_node *list_last(const struct list_node *head); // Get the number of list elements. size_t list_length(const struct list_node *head); diff --git a/src/commonlib/list.c b/src/commonlib/list.c index 9d11d9606c..1af92c8ac5 100644 --- a/src/commonlib/list.c +++ b/src/commonlib/list.c @@ -37,12 +37,15 @@ void list_append(struct list_node *node, struct list_node *head) list_insert_after(node, head); } -const struct list_node *list_last(const struct list_node *head) +struct list_node *list_last(const struct list_node *head) { - const struct list_node *ptr = head; + if (!head->next) + return NULL; + + struct list_node *ptr = head->next; while (ptr->next) ptr = ptr->next; - return ptr == head ? NULL : ptr; + return ptr; } size_t list_length(const struct list_node *head)