^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) struct list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) struct list *next, *prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) list_init(struct list *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) list->next = list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) list->prev = list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) list_empty(struct list *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) return list->next == list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) list_insert(struct list *link, struct list *new_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) new_link->prev = link->prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) new_link->next = link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) new_link->prev->next = new_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) new_link->next->prev = new_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) list_append(struct list *list, struct list *new_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) list_insert((struct list *)list, new_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) list_prepend(struct list *list, struct list *new_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) list_insert(list->next, new_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) list_remove(struct list *link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) link->prev->next = link->next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) link->next->prev = link->prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define list_entry(link, type, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ((type *)((char *)(link)-(unsigned long)(&((type *)0)->member)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define list_head(list, type, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) list_entry((list)->next, type, member)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define list_tail(list, type, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) list_entry((list)->prev, type, member)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define list_next(elm, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) list_entry((elm)->member.next, typeof(*elm), member)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define list_for_each_entry(pos, list, member) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) for (pos = list_head(list, typeof(*pos), member); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) &pos->member != (list); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) pos = list_next(pos, member))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)