summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Holland <[email protected]>2025-06-16 20:21:35 -0700
committerAnup Patel <[email protected]>2025-09-01 10:39:11 +0530
commit64a38525e6b00fa9bab704513b37adf8a89c3f03 (patch)
treedd2fa7e2f1c157feb7dfd2115b5c59d6f8ed59f7
parent1ffbd063c4da252f59cc570e537a3c8821ed6967 (diff)
lib: sbi_list: Add a helper for reverse list iteration
Some use cases require iterating through a list in both directions. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
-rw-r--r--include/sbi/sbi_list.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/sbi/sbi_list.h b/include/sbi/sbi_list.h
index be69fc43..587c655c 100644
--- a/include/sbi/sbi_list.h
+++ b/include/sbi/sbi_list.h
@@ -173,4 +173,15 @@ static inline void sbi_list_del_init(struct sbi_dlist *entry)
&pos->member != (head); \
pos = n, n = sbi_list_entry(pos->member.next, typeof(*pos), member))
+/**
+ * Iterate over list of given type in reverse order
+ * @param pos the type * to use as a loop cursor.
+ * @param head the head for your list.
+ * @param member the name of the list_struct within the struct.
+ */
+#define sbi_list_for_each_entry_reverse(pos, head, member) \
+ for (pos = sbi_list_entry((head)->prev, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = sbi_list_entry(pos->member.prev, typeof(*pos), member))
+
#endif