From: Simon Glass <sjg@chromium.org>
Date: Thu, 6 Oct 2016 02:42:12 +0000 (-0600)
Subject: list: Add list_last_entry() to find the last entry
X-Git-Tag: v2025.01-rc5-pxa1908~8327^2~35
X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-logo.png?a=commitdiff_plain;h=5023bd7a804e09d0bf4937d8fecb5d85af6dba3c;p=u-boot.git

list: Add list_last_entry() to find the last entry

We have list_first_entry() but in some cases it is useful to find the last
item added to the list. Add a macro for this.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

diff --git a/include/linux/list.h b/include/linux/list.h
index b78851c3d7..5b8d1df5df 100644
--- a/include/linux/list.h
+++ b/include/linux/list.h
@@ -337,6 +337,17 @@ static inline void list_splice_tail_init(struct list_head *list,
 #define list_first_entry(ptr, type, member) \
 	list_entry((ptr)->next, type, member)
 
+/**
+ * list_last_entry - get the last element from a list
+ * @ptr:	the list head to take the element from.
+ * @type:	the type of the struct this is embedded in.
+ * @member:	the name of the list_struct within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_last_entry(ptr, type, member) \
+	list_entry((ptr)->prev, type, member)
+
 /**
  * list_for_each	-	iterate over a list
  * @pos:	the &struct list_head to use as a loop cursor.