mirror of
https://github.com/OpenAMP/libmetal.git
synced 2026-08-18 11:29:49 +08:00
libmetal: add metal_list_for_each_safe() support
Add a more secure way to traverse linked lists Signed-off-by: Guiding Li <liguiding1@xiaomi.com>
This commit is contained in:
committed by
Arnaud Pouliquen
parent
0cb7d293a7
commit
e087ea5d38
+18
@@ -93,11 +93,29 @@ static inline struct metal_list *metal_list_first(struct metal_list *list)
|
||||
return metal_list_is_empty(list) ? NULL : list->next;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Used for iterating over a list
|
||||
*
|
||||
* @param list Pointer to the head node of the list
|
||||
* @param node Pointer to each node in the list during iteration
|
||||
*/
|
||||
#define metal_list_for_each(list, node) \
|
||||
for ((node) = (list)->next; \
|
||||
(node) != (list); \
|
||||
(node) = (node)->next)
|
||||
|
||||
/**
|
||||
* @brief Used for iterating over a list safely
|
||||
*
|
||||
* @param list Pointer to the head node of the list
|
||||
* @param temp Pointer to the next node's address during iteration
|
||||
* @param node Pointer to each node in the list during iteration
|
||||
*/
|
||||
#define metal_list_for_each_safe(list, temp, node) \
|
||||
for ((node) = (list)->next, (temp) = (node)->next; \
|
||||
(node) != (list); \
|
||||
(node) = (temp), (temp) = (node)->next)
|
||||
|
||||
static inline bool metal_list_find_node(struct metal_list *list,
|
||||
struct metal_list *node)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user