]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
module: make structure definitions always visible
authorThomas Weißschuh <thomas.weissschuh@linutronix.de>
Fri, 11 Jul 2025 13:31:37 +0000 (15:31 +0200)
committerDaniel Gomez <da.gomez@samsung.com>
Thu, 31 Jul 2025 11:51:25 +0000 (13:51 +0200)
To write code that works with both CONFIG_MODULES=y and CONFIG_MODULES=n
it is convenient to use "if (IS_ENABLED(CONFIG_MODULES))" over raw #ifdef.
The code will still fully typechecked but the unreachable parts are
discarded by the compiler. This prevents accidental breakage when a certain
kconfig combination was not specifically tested by the developer.
This pattern is already supported to some extend by module.h defining
empty stub functions if CONFIG_MODULES=n.
However some users of module.h work on the structured defined by module.h.

Therefore these structure definitions need to be visible, too.

Many structure members are still gated by specific configuration settings.
The assumption for those is that the code using them will be gated behind
the same configuration setting anyways.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Reviewed-by: Daniel Gomez <da.gomez@samsung.com>
Link: https://lore.kernel.org/r/20250711-kunit-ifdef-modules-v2-2-39443decb1f8@linutronix.de
Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
include/linux/module.h

index 97c38e1cd37783170650b4a80de69af14e7115fd..5fe812de2d84cc26d13fffc2298137298e6f92e2 100644 (file)
@@ -303,16 +303,6 @@ static typeof(name) __mod_device_table__##type##__##name           \
 
 struct notifier_block;
 
-#ifdef CONFIG_MODULES
-
-/* Get/put a kernel symbol (calls must be symmetric) */
-void *__symbol_get(const char *symbol);
-void *__symbol_get_gpl(const char *symbol);
-#define symbol_get(x)  ({ \
-       static const char __notrim[] \
-               __used __section(".no_trim_symbol") = __stringify(x); \
-       (typeof(&x))(__symbol_get(__stringify(x))); })
-
 enum module_state {
        MODULE_STATE_LIVE,      /* Normal state. */
        MODULE_STATE_COMING,    /* Full formed, running module_init. */
@@ -597,6 +587,16 @@ struct module {
 #define MODULE_ARCH_INIT {}
 #endif
 
+#ifdef CONFIG_MODULES
+
+/* Get/put a kernel symbol (calls must be symmetric) */
+void *__symbol_get(const char *symbol);
+void *__symbol_get_gpl(const char *symbol);
+#define symbol_get(x)  ({ \
+       static const char __notrim[] \
+               __used __section(".no_trim_symbol") = __stringify(x); \
+       (typeof(&x))(__symbol_get(__stringify(x))); })
+
 #ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
 static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
 {