[PATCH 1/3] test: self: idr: add test for idr_remove in idr_for_each_entry
Ahmad Fatoum
a.fatoum at barebox.org
Sun Jun 22 23:26:39 PDT 2025
If we have had this test earlier, it would have caught that
idr_for_each_entry didn't guarantee safe iteration while freeing.
Add a test, so we may catach future issues of this sort.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
test/self/idr.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/test/self/idr.c b/test/self/idr.c
index cc3217bb06e4..bc68a84be4ce 100644
--- a/test/self/idr.c
+++ b/test/self/idr.c
@@ -73,9 +73,17 @@ static void test_idr(void)
id = idr_alloc_one(&idr, &cmp[2], cmp[2]);
expect(id == cmp[2]);
+ id = idr_alloc_one(&idr, NULL, 4);
+ expect(id == 4);
+
count = 0;
idr_for_each_entry(&idr, ptr, id) {
+ if (id == 4) {
+ idr_remove(&idr, 4);
+ continue;
+ }
+
expect(id == sorted_cmp[count]);
expect(*(int *)ptr == sorted_cmp[count]);
--
2.39.5
More information about the barebox
mailing list