18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_cistruct list { 38c2ecf20Sopenharmony_ci struct list *next, *prev; 48c2ecf20Sopenharmony_ci}; 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_cistatic inline void 78c2ecf20Sopenharmony_cilist_init(struct list *list) 88c2ecf20Sopenharmony_ci{ 98c2ecf20Sopenharmony_ci list->next = list; 108c2ecf20Sopenharmony_ci list->prev = list; 118c2ecf20Sopenharmony_ci} 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic inline int 148c2ecf20Sopenharmony_cilist_empty(struct list *list) 158c2ecf20Sopenharmony_ci{ 168c2ecf20Sopenharmony_ci return list->next == list; 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic inline void 208c2ecf20Sopenharmony_cilist_insert(struct list *link, struct list *new_link) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci new_link->prev = link->prev; 238c2ecf20Sopenharmony_ci new_link->next = link; 248c2ecf20Sopenharmony_ci new_link->prev->next = new_link; 258c2ecf20Sopenharmony_ci new_link->next->prev = new_link; 268c2ecf20Sopenharmony_ci} 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_cistatic inline void 298c2ecf20Sopenharmony_cilist_append(struct list *list, struct list *new_link) 308c2ecf20Sopenharmony_ci{ 318c2ecf20Sopenharmony_ci list_insert((struct list *)list, new_link); 328c2ecf20Sopenharmony_ci} 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic inline void 358c2ecf20Sopenharmony_cilist_prepend(struct list *list, struct list *new_link) 368c2ecf20Sopenharmony_ci{ 378c2ecf20Sopenharmony_ci list_insert(list->next, new_link); 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistatic inline void 418c2ecf20Sopenharmony_cilist_remove(struct list *link) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci link->prev->next = link->next; 448c2ecf20Sopenharmony_ci link->next->prev = link->prev; 458c2ecf20Sopenharmony_ci} 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define list_entry(link, type, member) \ 488c2ecf20Sopenharmony_ci ((type *)((char *)(link)-(unsigned long)(&((type *)0)->member))) 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ci#define list_head(list, type, member) \ 518c2ecf20Sopenharmony_ci list_entry((list)->next, type, member) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define list_tail(list, type, member) \ 548c2ecf20Sopenharmony_ci list_entry((list)->prev, type, member) 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci#define list_next(elm, member) \ 578c2ecf20Sopenharmony_ci list_entry((elm)->member.next, typeof(*elm), member) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define list_for_each_entry(pos, list, member) \ 608c2ecf20Sopenharmony_ci for (pos = list_head(list, typeof(*pos), member); \ 618c2ecf20Sopenharmony_ci &pos->member != (list); \ 628c2ecf20Sopenharmony_ci pos = list_next(pos, member)) 638c2ecf20Sopenharmony_ci 64