From 526e32130c2237b0a48a73db0c46002e7ade7f52 Mon Sep 17 00:00:00 2001 From: Tammy Leino Date: Fri, 23 Sep 2022 10:56:31 -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 d1286c30..9e901c9f 100644 --- a/lib/list.h +++ b/lib/list.h @@ -13,6 +13,7 @@ #define __METAL_LIST__H__ #include +#include #ifdef __cplusplus extern "C" { @@ -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