summaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorYury Norov <ynorov@nvidia.com>2026-09-11 18:14:42 -0400
committerAndrew Morton <akpm@linux-foundation.org>2026-10-08 22:55:12 -0700
commit2233228b65291f8e9b04ee8be52bd2f694e12889 (patch)
treed2178bee08a85c31deacc4a0fe645e2b740b2cff /include/linux
parentc3f25ea70432ac917e1881b08e62732f3cf33f97 (diff)
downloadlinux-2233228b65291f8e9b04ee8be52bd2f694e12889.tar.gz
linux-2233228b65291f8e9b04ee8be52bd2f694e12889.zip
idr: assert static storage for DEFINE_IDA()
DEFINE_IDA() uses IDA_INIT(), which initializes the embedded XArray lock with a static spinlock initializer. For an automatic local IDA, lockdep cannot use the lock address as a persistent class key and reports "INFO: trying to register non-static key" before disabling itself. Apply ASSERT_STATIC_STORAGE() to DEFINE_IDA() so that this misuse is rejected at compile time. For example: void example(void) { DEFINE_IDA(ida); ida_destroy(&ida); } GCC reports: error: initializer element is not constant name##_storage_check = &(name) ^ note: in expansion of macro 'ASSERT_STATIC_STORAGE' ASSERT_STATIC_STORAGE(name) note: in expansion of macro 'DEFINE_IDA' DEFINE_IDA(ida); File-scope definitions and static DEFINE_IDA() within a function remain valid. Automatic local IDAs must instead be initialized with ida_init(). Direct uses of IDA_INIT() are not covered by this declaration check. Convert the five automatic local IDAs in the userspace radix-tree tests to ida_init() so they satisfy the new requirement. Validated file-scope and static local definitions with a kernel object build, and confirmed that an automatic local definition fails to compile. Link: https://lore.kernel.org/20260911221444.1523311-3-ynorov@nvidia.com Signed-off-by: Yury Norov <ynorov@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Andrew Ballance <andrewjballance@gmail.com> Cc: Christopher Li <sparse@chrisli.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/idr.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/linux/idr.h b/include/linux/idr.h
index 789e23e67444..e2a4b6298511 100644
--- a/include/linux/idr.h
+++ b/include/linux/idr.h
@@ -16,6 +16,7 @@
#include <linux/gfp.h>
#include <linux/percpu.h>
#include <linux/cleanup.h>
+#include <linux/compiler.h>
struct idr {
struct radix_tree_root idr_rt;
@@ -269,7 +270,9 @@ struct ida {
#define IDA_INIT(name) { \
.xa = XARRAY_INIT(name, IDA_INIT_FLAGS) \
}
-#define DEFINE_IDA(name) struct ida name = IDA_INIT(name)
+#define DEFINE_IDA(name) \
+ struct ida name = IDA_INIT(name); \
+ ASSERT_STATIC_STORAGE(name)
int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t);
void ida_free(struct ida *, unsigned int id);