diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/linked_list.c | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/firmware/common/linked_list.c b/firmware/common/linked_list.c index 006caacc91..a5b3de3cf7 100644 --- a/firmware/common/linked_list.c +++ b/firmware/common/linked_list.c | |||
@@ -60,26 +60,14 @@ void ll_init(struct ll_head *list) | |||
60 | void ll_insert_next(struct ll_head *list, struct ll_node *node, | 60 | void ll_insert_next(struct ll_head *list, struct ll_node *node, |
61 | struct ll_node *newnode) | 61 | struct ll_node *newnode) |
62 | { | 62 | { |
63 | if (node == NULL) | 63 | struct ll_node **nodep = node != NULL ? &node->next : &list->head; |
64 | { | 64 | struct ll_node *next = *nodep; |
65 | node = list->head; | ||
66 | |||
67 | newnode->next = node; | ||
68 | list->head = newnode; | ||
69 | |||
70 | if (node == NULL) | ||
71 | list->tail = node; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | struct ll_node *next = node->next; | ||
76 | 65 | ||
77 | newnode->next = next; | 66 | newnode->next = next; |
78 | node->next = newnode; | 67 | *nodep = newnode; |
79 | 68 | ||
80 | if (next == NULL) | 69 | if (next == NULL) |
81 | list->tail = newnode; | 70 | list->tail = newnode; |
82 | } | ||
83 | } | 71 | } |
84 | 72 | ||
85 | /** | 73 | /** |
@@ -117,27 +105,16 @@ void ll_insert_last(struct ll_head *list, struct ll_node *node) | |||
117 | */ | 105 | */ |
118 | void ll_remove_next(struct ll_head *list, struct ll_node *node) | 106 | void ll_remove_next(struct ll_head *list, struct ll_node *node) |
119 | { | 107 | { |
120 | if (node == NULL) | 108 | struct ll_node **nodep = node != NULL ? &node->next : &list->head; |
121 | { | 109 | struct ll_node *next = *nodep; |
122 | node = list->head->next; | ||
123 | |||
124 | list->head = node; | ||
125 | 110 | ||
126 | if (node == NULL) | 111 | if (next != NULL) |
127 | list->tail = NULL; | ||
128 | } | ||
129 | else | ||
130 | { | 112 | { |
131 | struct ll_node *next = node->next; | 113 | next = next->next; |
132 | 114 | *nodep = next; | |
133 | if (next != NULL) | ||
134 | { | ||
135 | next = next->next; | ||
136 | node->next = next; | ||
137 | 115 | ||
138 | if (!next) | 116 | if (next == NULL) |
139 | list->tail = node; | 117 | list->tail = node; |
140 | } | ||
141 | } | 118 | } |
142 | } | 119 | } |
143 | 120 | ||