mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH master 2/4] lib: idr: make idr_for_each_entry removal safe
Date: Mon, 23 Jun 2025 08:20:30 +0200	[thread overview]
Message-ID: <20250623062032.3527006-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250623062032.3527006-1-a.fatoum@barebox.org>

There's no idr_for_each_entry_safe and the Linux implementation of
idr_for_each_entry already allows to free while iterating and indeed,
the newly introduced 9P file system makes use of exactly that.

The barebox implementation is home-grown, because we didn't yet import
radix tree support and it did not allow freeing during iteration.

Rework our macro to allow this.

Fixes: d28d3d9159a1 ("include: linux/idr.h: implement more Linux API")
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 include/linux/idr.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/linux/idr.h b/include/linux/idr.h
index 07adde713477..e726d17b591f 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -37,9 +37,10 @@ struct idr {
  */
 #define idr_for_each_entry(_idr, _entry, _id)				\
 	for (struct idr *iter =						\
-	     list_first_entry_or_null(&(_idr)->list, struct idr, list);	\
-	     (iter && iter != (_idr)) || (_entry = NULL);	\
-	     iter = list_next_entry(iter, list))			\
+	     list_first_entry_or_null(&(_idr)->list, struct idr, list), \
+	     *tmp = iter ? list_next_entry(iter, list) : NULL;		\
+	     (iter && iter != (_idr)) || (_entry = NULL);		\
+	     iter = tmp, tmp = tmp ?  list_next_entry(tmp, list) : NULL)\
 	if ((_entry = iter->ptr, _id = iter->id, true))
 
 struct idr *__idr_find(struct idr *head, int lookup_id);
-- 
2.39.5




  reply	other threads:[~2025-06-23  6:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-23  6:20 [PATCH master 1/4] commands: stat: fix leaking file descriptors on early exit Ahmad Fatoum
2025-06-23  6:20 ` Ahmad Fatoum [this message]
2025-06-23  6:20 ` [PATCH master 3/4] startup: track system state with regards to initcall/exitcalls Ahmad Fatoum
2025-06-23  6:20 ` [PATCH master 4/4] fs: do not skip fs_remove when calling umount ramfs Ahmad Fatoum
2025-06-23  8:36 ` [PATCH master 1/4] commands: stat: fix leaking file descriptors on early exit Sascha Hauer

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=20250623062032.3527006-2-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /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