]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
kconfig: import more list macros and inline functions
authorMasahiro Yamada <masahiroy@kernel.org>
Fri, 2 Feb 2024 15:58:19 +0000 (00:58 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Mon, 19 Feb 2024 09:20:41 +0000 (18:20 +0900)
Import more macros and inline functions from include/linux/list.h
and include/linux/types.h.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
scripts/kconfig/list.h
scripts/kconfig/list_types.h

index 2bce2b8f21d136b836bd633582ddba4129d6be5f..882859ddf9f4f94cba26f3d5ab41fe9be04448d4 100644 (file)
@@ -70,6 +70,19 @@ static inline void __list_add(struct list_head *new,
        prev->next = new;
 }
 
+/**
+ * list_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void list_add(struct list_head *new, struct list_head *head)
+{
+       __list_add(new, head, head->next);
+}
+
 /**
  * list_add_tail - add a new entry
  * @new: new entry to be added
@@ -114,6 +127,16 @@ static inline void list_del(struct list_head *entry)
        entry->prev = LIST_POISON2;
 }
 
+/**
+ * list_is_head - tests whether @list is the list @head
+ * @list: the entry to test
+ * @head: the head of the list
+ */
+static inline int list_is_head(const struct list_head *list, const struct list_head *head)
+{
+       return list == head;
+}
+
 /**
  * list_empty - tests whether a list is empty
  * @head: the list to test.
@@ -184,4 +207,50 @@ static inline int list_empty(const struct list_head *head)
             !list_entry_is_head(pos, head, member);                    \
             pos = n, n = list_next_entry(n, member))
 
+/*
+ * Double linked lists with a single pointer list head.
+ * Mostly useful for hash tables where the two pointer list head is
+ * too wasteful.
+ * You lose the ability to access the tail in O(1).
+ */
+
+#define HLIST_HEAD_INIT { .first = NULL }
+
+/**
+ * hlist_add_head - add a new entry at the beginning of the hlist
+ * @n: new entry to be added
+ * @h: hlist head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
+{
+       struct hlist_node *first = h->first;
+
+       n->next = first;
+       if (first)
+               first->pprev = &n->next;
+       h->first = n;
+       n->pprev = &h->first;
+}
+
+#define hlist_entry(ptr, type, member) container_of(ptr, type, member)
+
+#define hlist_entry_safe(ptr, type, member) \
+       ({ typeof(ptr) ____ptr = (ptr); \
+          ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
+       })
+
+/**
+ * hlist_for_each_entry        - iterate over list of given type
+ * @pos:       the type * to use as a loop cursor.
+ * @head:      the head for your list.
+ * @member:    the name of the hlist_node within the struct.
+ */
+#define hlist_for_each_entry(pos, head, member)                                \
+       for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\
+            pos;                                                       \
+            pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member))
+
 #endif /* LIST_H */
index 32899f424983e100bb9c9bbf900dd1b9d4de2149..d935b7c5aa8137f4b7faba0293839bec912f3e67 100644 (file)
@@ -6,4 +6,12 @@ struct list_head {
        struct list_head *next, *prev;
 };
 
+struct hlist_head {
+       struct hlist_node *first;
+};
+
+struct hlist_node {
+       struct hlist_node *next, **pprev;
+};
+
 #endif /* LIST_TYPES_H */