aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/linux/llist.h2
-rw-r--r--lib/llist.c22
2 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/llist.h b/include/linux/llist.h
index 197228346..6c690687b 100644
--- a/include/linux/llist.h
+++ b/include/linux/llist.h
@@ -212,4 +212,6 @@ extern bool llist_add_batch(struct llist_node *new_first,
struct llist_head *head);
extern struct llist_node *llist_del_first(struct llist_head *head);
+struct llist_node *llist_reverse_order(struct llist_node *head);
+
#endif /* LLIST_H */
diff --git a/lib/llist.c b/lib/llist.c
index 4a15115e9..36d657c0c 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -86,3 +86,25 @@ struct llist_node *llist_del_first(struct llist_head *head)
return entry;
}
EXPORT_SYMBOL_GPL(llist_del_first);
+
+/**
+ * llist_reverse_order - reverse order of a llist chain
+ * @head: first item of the list to be reversed
+ *
+ * Reverse the oder of a chain of llist entries and return the
+ * new first entry.
+ */
+struct llist_node *llist_reverse_order(struct llist_node *head)
+{
+ struct llist_node *new_head = NULL;
+
+ while (head) {
+ struct llist_node *tmp = head;
+ head = head->next;
+ tmp->next = new_head;
+ new_head = tmp;
+ }
+
+ return new_head;
+}
+EXPORT_SYMBOL_GPL(llist_reverse_order);