public inbox for opensbi@lists.infradead.org
 help / color / mirror / Atom feed
From: Anup Patel <anup@brainfault.org>
To: Yong-Xuan Wang <yongxuan.wang@sifive.com>
Cc: opensbi@lists.infradead.org, greentime.hu@sifive.com,
	 vincent.chen@sifive.com
Subject: Re: [PATCH 1/1] lib: sbi_list: add a helper for safe list iteration
Date: Sun, 20 Jul 2025 20:47:25 +0530	[thread overview]
Message-ID: <CAAhSdy2w4kBP1CYGRvppAkJs8h6_VoAdPykinfBU2NsSWaTOsg@mail.gmail.com> (raw)
In-Reply-To: <20250618025416.5331-1-yongxuan.wang@sifive.com>

On Wed, Jun 18, 2025 at 8:24 AM Yong-Xuan Wang <yongxuan.wang@sifive.com> wrote:
>
> Some use cases require iterating safe against removal of list entry.
>
> Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com>

LGTM.

Reviewed-by: Anup Patel <anup@brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
>  include/sbi/sbi_list.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/include/sbi/sbi_list.h b/include/sbi/sbi_list.h
> index 9e56c526faf2..be69fc4314e0 100644
> --- a/include/sbi/sbi_list.h
> +++ b/include/sbi/sbi_list.h
> @@ -160,4 +160,17 @@ static inline void sbi_list_del_init(struct sbi_dlist *entry)
>              &pos->member != (head);    \
>              pos = sbi_list_entry(pos->member.next, typeof(*pos), member))
>
> +/**
> + * Iterate over list of given type safe against removal of list entry
> + * @param pos the type * to use as a loop cursor.
> + * @param n another type * to use as temporary storage.
> + * @param head the head for your list.
> + * @param member the name of the list_struct within the struct.
> + */
> +#define sbi_list_for_each_entry_safe(pos, n, head, member) \
> +       for (pos = sbi_list_entry((head)->next, typeof(*pos), member),  \
> +            n = sbi_list_entry(pos->member.next, typeof(*pos), member);        \
> +            &pos->member != (head);    \
> +            pos = n, n = sbi_list_entry(pos->member.next, typeof(*pos), member))
> +
>  #endif
> --
> 2.17.1
>

-- 
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

      reply	other threads:[~2025-07-20 15:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-18  2:54 [PATCH 1/1] lib: sbi_list: add a helper for safe list iteration Yong-Xuan Wang
2025-07-20 15:17 ` Anup Patel [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAAhSdy2w4kBP1CYGRvppAkJs8h6_VoAdPykinfBU2NsSWaTOsg@mail.gmail.com \
    --to=anup@brainfault.org \
    --cc=greentime.hu@sifive.com \
    --cc=opensbi@lists.infradead.org \
    --cc=vincent.chen@sifive.com \
    --cc=yongxuan.wang@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox