[patch 05/38] btree: Initialize early when builtin

Thomas Gleixner
2022-07-16T23:17:33Z

An upcoming user of btree needs it early on. Initialize it in
start_kernel().

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
include/linux/btree.h | 6 ++++++
init/main.c | 2 ++
lib/btree.c | 8 +++++++-
3 files changed, 15 insertions(+), 1 deletion(-)

--- a/include/linux/btree.h
+++ b/include/linux/btree.h
@@ -5,6 +5,12 @@
#include <linux/kernel.h>
#include <linux/mempool.h>

+#if IS_BUILTIN(CONFIG_BTREE)
+extern void btree_cache_init(void);
+#else
+static inline void btree_cache_init(void) {}
+#endif
+
/**
* DOC: B+Tree basics
*
--- a/init/main.c
+++ b/init/main.c
@@ -75,6 +75,7 @@
#include <linux/signal.h>
#include <linux/idr.h>
#include <linux/kgdb.h>
+#include <linux/btree.h>
#include <linux/ftrace.h>
#include <linux/async.h>
#include <linux/shmem_fs.h>
@@ -1125,6 +1126,7 @@ asmlinkage __visible void __init __no_sa
cgroup_init();
taskstats_init_early();
delayacct_init();
+ btree_cache_init();

poking_init();
check_bugs();
--- a/lib/btree.c
+++ b/lib/btree.c
@@ -787,15 +787,21 @@ static int __init btree_module_init(void
return 0;
}

+#if IS_MODULE(CONFIG_BTREE)
static void __exit btree_module_exit(void)
{
kmem_cache_destroy(btree_cachep);
}

-/* If core code starts using btree, initialization should happen even earlier */
module_init(btree_module_init);
module_exit(btree_module_exit);

MODULE_AUTHOR("Joern Engel <joern@logfs.org>");
MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
MODULE_LICENSE("GPL");
+#else
+void __init btree_cache_init(void)
+{
+ BUG_ON(btree_module_init());
+}
+#endif