1aa2be509SMichael Wildt /* SPDX-License-Identifier: BSD-3-Clause 2*e6e8f03eSRandy Schacher * Copyright(c) 2019-2023 Broadcom 3aa2be509SMichael Wildt * All rights reserved. 4aa2be509SMichael Wildt */ 5aa2be509SMichael Wildt 6aa2be509SMichael Wildt /* Linked List Functions */ 7aa2be509SMichael Wildt 8aa2be509SMichael Wildt #include <stdio.h> 9aa2be509SMichael Wildt #include "ll.h" 10aa2be509SMichael Wildt 11aa2be509SMichael Wildt /* init linked list */ ll_init(struct ll * ll)12aa2be509SMichael Wildtvoid ll_init(struct ll *ll) 13aa2be509SMichael Wildt { 14aa2be509SMichael Wildt ll->head = NULL; 15aa2be509SMichael Wildt ll->tail = NULL; 1637ff91c1SFarah Smith ll->cnt = 0; 17aa2be509SMichael Wildt } 18aa2be509SMichael Wildt 19aa2be509SMichael Wildt /* insert entry in linked list */ ll_insert(struct ll * ll,struct ll_entry * entry)20aa2be509SMichael Wildtvoid ll_insert(struct ll *ll, 21aa2be509SMichael Wildt struct ll_entry *entry) 22aa2be509SMichael Wildt { 23aa2be509SMichael Wildt if (ll->head == NULL) { 24aa2be509SMichael Wildt ll->head = entry; 25aa2be509SMichael Wildt ll->tail = entry; 26aa2be509SMichael Wildt entry->next = NULL; 27aa2be509SMichael Wildt entry->prev = NULL; 28aa2be509SMichael Wildt } else { 29aa2be509SMichael Wildt entry->next = ll->head; 30aa2be509SMichael Wildt entry->prev = NULL; 31aa2be509SMichael Wildt entry->next->prev = entry; 32aa2be509SMichael Wildt ll->head = entry->next->prev; 33aa2be509SMichael Wildt } 3437ff91c1SFarah Smith ll->cnt++; 35aa2be509SMichael Wildt } 36aa2be509SMichael Wildt 37aa2be509SMichael Wildt /* delete entry from linked list */ ll_delete(struct ll * ll,struct ll_entry * entry)38aa2be509SMichael Wildtvoid ll_delete(struct ll *ll, 39aa2be509SMichael Wildt struct ll_entry *entry) 40aa2be509SMichael Wildt { 41aa2be509SMichael Wildt if (ll->head == entry && ll->tail == entry) { 42aa2be509SMichael Wildt ll->head = NULL; 43aa2be509SMichael Wildt ll->tail = NULL; 44aa2be509SMichael Wildt } else if (ll->head == entry) { 45aa2be509SMichael Wildt ll->head = entry->next; 46aa2be509SMichael Wildt ll->head->prev = NULL; 47aa2be509SMichael Wildt } else if (ll->tail == entry) { 48aa2be509SMichael Wildt ll->tail = entry->prev; 49aa2be509SMichael Wildt ll->tail->next = NULL; 50aa2be509SMichael Wildt } else { 51aa2be509SMichael Wildt entry->prev->next = entry->next; 52aa2be509SMichael Wildt entry->next->prev = entry->prev; 53aa2be509SMichael Wildt } 5437ff91c1SFarah Smith ll->cnt--; 55aa2be509SMichael Wildt } 56