[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aShYJta2EHh1d8az@casper.infradead.org>
Date: Thu, 27 Nov 2025 13:54:46 +0000
From: Matthew Wilcox <willy@...radead.org>
To: Jan Sokolowski <jan.sokolowski@...el.com>
Cc: linux-kernel@...r.kernel.org,
Christian König <christian.koenig@....com>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-fsdevel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [RFC PATCH 1/1] idr: do not create idr if new id would be
outside given range
On Thu, Nov 27, 2025 at 10:27:32AM +0100, Jan Sokolowski wrote:
> A scenario was found where trying to add id in range 0,1
> would return an id of 2, which is outside the range and thus
> now what the user would expect.
Can you do a bit better with this bug report? Under what circumstances
does this happen? Preferably answer in the form of a test case for the
IDR test suite. Here's my attempt to recreate your situation based on
what I read in that thread. It doesn't show a problem, so clearly I got
something wrong.
To run the test suite, apply this patch, then
$ make -C tools/testing/radix-tree
$ ./tools/testing/radix-tree/idr-test
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index 2f830ff8396c..774c0c9c141f 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -57,6 +57,21 @@ void idr_alloc_test(void)
idr_destroy(&idr);
}
+void idr_alloc2_test(void)
+{
+ int id;
+ DEFINE_IDR(idr);
+
+ id = idr_alloc(&idr, idr_alloc2_test, 0, 1, GFP_KERNEL);
+ printf("id = %d\n", id);
+ assert(id == 0);
+ id = idr_alloc(&idr, idr_alloc2_test, 0, 1, GFP_KERNEL);
+ printf("id = %d\n", id);
+ assert(id == -ENOSPC);
+
+ idr_destroy(&idr);
+}
+
void idr_replace_test(void)
{
DEFINE_IDR(idr);
@@ -409,6 +424,7 @@ void idr_checks(void)
idr_replace_test();
idr_alloc_test();
+ idr_alloc2_test();
idr_null_test();
idr_nowait_test();
idr_get_next_test(0);
Powered by blists - more mailing lists