Skip to content

Commit 818783c

Browse files
t-8chdkruces
authored andcommitted
module: make structure definitions always visible
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 <[email protected]> Reviewed-by: Daniel Gomez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Gomez <[email protected]>
1 parent 199d9ff commit 818783c

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

include/linux/module.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,6 @@ static typeof(name) __mod_device_table__##type##__##name \
303303

304304
struct notifier_block;
305305

306-
#ifdef CONFIG_MODULES
307-
308-
/* Get/put a kernel symbol (calls must be symmetric) */
309-
void *__symbol_get(const char *symbol);
310-
void *__symbol_get_gpl(const char *symbol);
311-
#define symbol_get(x) ({ \
312-
static const char __notrim[] \
313-
__used __section(".no_trim_symbol") = __stringify(x); \
314-
(typeof(&x))(__symbol_get(__stringify(x))); })
315-
316306
enum module_state {
317307
MODULE_STATE_LIVE, /* Normal state. */
318308
MODULE_STATE_COMING, /* Full formed, running module_init. */
@@ -597,6 +587,16 @@ struct module {
597587
#define MODULE_ARCH_INIT {}
598588
#endif
599589

590+
#ifdef CONFIG_MODULES
591+
592+
/* Get/put a kernel symbol (calls must be symmetric) */
593+
void *__symbol_get(const char *symbol);
594+
void *__symbol_get_gpl(const char *symbol);
595+
#define symbol_get(x) ({ \
596+
static const char __notrim[] \
597+
__used __section(".no_trim_symbol") = __stringify(x); \
598+
(typeof(&x))(__symbol_get(__stringify(x))); })
599+
600600
#ifndef HAVE_ARCH_KALLSYMS_SYMBOL_VALUE
601601
static inline unsigned long kallsyms_symbol_value(const Elf_Sym *sym)
602602
{

0 commit comments

Comments
 (0)