1 /* Copyright (c) 2019 The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions 5 * are met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above copyright 9 * notice, this list of conditions and the following disclaimer in 10 * the documentation and/or other materials provided with the 11 * distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef _WIFIHAL_LIST_H_ 30 #define _WIFIHAL_LIST_H_ 31 32 struct list_head { 33 struct list_head *next, *prev; 34 }; 35 36 void INITIALISE_LIST(struct list_head *list); 37 void list_add(struct list_head *latest, struct list_head *prev, 38 struct list_head *next); 39 void add_to_list(struct list_head *latest, struct list_head *head); 40 void list_add_tail(struct list_head *latest, struct list_head *head); 41 void list_del(struct list_head *prev, struct list_head *next); 42 void del_from_list(struct list_head *record); 43 void replace_in_list(struct list_head *old, struct list_head *latest); 44 45 #define list_for_each(ref, head) \ 46 for (ref = (head)->next; ref->next, ref != (head); ref = ref->next) 47 48 #define offset_of(type, member) ((char *)&((type *)0)->member) 49 50 #define container_of(ptr, type, member) ({ \ 51 const typeof(((type *)0)->member) *__mptr = (ptr); \ 52 (type *)((char *)__mptr - offset_of(type, member)); }) 53 54 #define list_entry(ptr, type, member) \ 55 container_of(ptr, type, member) 56 57 #define list_for_each_entry(ref, head, member) \ 58 for (ref = list_entry((head)->next, typeof(*ref), member); \ 59 ref->member.next, &ref->member != (head); \ 60 ref = list_entry(ref->member.next, typeof(*ref), member)) 61 62 #define list_for_each_entry_safe(pos, n, head, member) \ 63 for (pos = list_entry((head)->next, typeof(*pos), member), \ 64 n = list_entry(pos->member.next, typeof(*pos), member); \ 65 &pos->member != (head); \ 66 pos = n, n = list_entry(n->member.next, typeof(*n), member)) 67 68 #define list_for_each_safe(pos, n, head) \ 69 for (pos = (head)->next, n = pos->next; pos != (head); \ 70 pos = n, n = pos->next) 71 72 #endif 73