summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2024-02-03 00:58:19 +0900
committerMasahiro Yamada <masahiroy@kernel.org>2024-02-19 18:20:41 +0900
commit5e3cf304a0bdc7a3d7ba4805bb2bb05c5e6916ff (patch)
tree58cd6fd1135e6b3d9929c6cba1b93c3415da9d71 /scripts
parent55f649b73de1585de8608ad5afa764cd7646f9c2 (diff)
downloadlinux-stable-5e3cf304a0bdc7a3d7ba4805bb2bb05c5e6916ff.tar.gz
linux-stable-5e3cf304a0bdc7a3d7ba4805bb2bb05c5e6916ff.tar.bz2
linux-stable-5e3cf304a0bdc7a3d7ba4805bb2bb05c5e6916ff.zip
kconfig: import more list macros and inline functions
Import more macros and inline functions from include/linux/list.h and include/linux/types.h. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/kconfig/list.h69
-rw-r--r--scripts/kconfig/list_types.h8
2 files changed, 77 insertions, 0 deletions
diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h
index 2bce2b8f21d1..882859ddf9f4 100644
--- a/scripts/kconfig/list.h
+++ b/scripts/kconfig/list.h
@@ -71,6 +71,19 @@ static inline void __list_add(struct list_head *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
* @head: list head to add it before
@@ -115,6 +128,16 @@ static inline void list_del(struct list_head *entry)
}
/**
+ * 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 */
diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h
index 32899f424983..d935b7c5aa81 100644
--- a/scripts/kconfig/list_types.h
+++ b/scripts/kconfig/list_types.h
@@ -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 */