From c1c4e5599268a211860cfed2fd0b344ded57498c Mon Sep 17 00:00:00 2001 From: Tammy Leino Date: Mon, 3 Oct 2022 11:52:37 -0700 Subject: [PATCH] New routine to find a node on a list metal_list_find_node is used to ensure a node is not on a list before adding it Signed-off-by: Tammy Leino --- lib/list.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/list.h b/lib/list.h index d1286c3..eb0e7b3 100644 --- a/lib/list.h +++ b/lib/list.h @@ -12,6 +12,7 @@ #ifndef __METAL_LIST__H__ #define __METAL_LIST__H__ +#include #include #ifdef __cplusplus @@ -96,6 +97,18 @@ static inline struct metal_list *metal_list_first(struct metal_list *list) for ((node) = (list)->next; \ (node) != (list); \ (node) = (node)->next) + +static inline bool metal_list_find_node(struct metal_list *list, + struct metal_list *node) +{ + struct metal_list *n; + + metal_list_for_each(list, n) { + if (n == node) + return true; + } + return false; +} /** @} */ #ifdef __cplusplus