diff --git a/src/include/gpxe/list.h b/src/include/gpxe/list.h index 7c6042b2..0e65901c 100644 --- a/src/include/gpxe/list.h +++ b/src/include/gpxe/list.h @@ -138,8 +138,23 @@ static inline int list_empty ( const struct list_head *head ) { * @v member The name of the list_struct within the struct */ #define list_for_each_entry( pos, head, member ) \ - for ( pos = list_entry ( (head)->next, typeof ( *pos ), member); \ + for ( pos = list_entry ( (head)->next, typeof ( *pos ), member ); \ &pos->member != (head); \ pos = list_entry ( pos->member.next, typeof ( *pos ), member ) ) +/** + * Iterate over entries in a list, safe against deletion of entries + * + * @v pos The type * to use as a loop counter + * @v tmp Another type * to use for temporary storage + * @v head The head for your list + * @v member The name of the list_struct within the struct + */ +#define list_for_each_entry_safe( pos, tmp, head, member ) \ + for ( pos = list_entry ( (head)->next, typeof ( *pos ), member ), \ + tmp = list_entry ( pos->member.next, typeof ( *tmp ), member ); \ + &pos->member != (head); \ + pos = tmp, \ + tmp = list_entry ( tmp->member.next, typeof ( *tmp ), member ) ) + #endif /* _GPXE_LIST_H */