Skip to content

Commit a64fb3c

Browse files
Paul Gortmakertorvalds
authored andcommitted
mm: audit/fix non-modular users of module_init in core code
Code that is obj-y (always built-in) or dependent on a bool Kconfig (built-in or absent) can never be modular. So using module_init as an alias for __initcall can be somewhat misleading. Fix these up now, so that we can relocate module_init from init.h into module.h in the future. If we don't do this, we'd have to add module.h to obviously non-modular code, and that would be a worse thing. The audit targets the following module_init users for change: mm/ksm.c bool KSM mm/mmap.c bool MMU mm/huge_memory.c bool TRANSPARENT_HUGEPAGE mm/mmu_notifier.c bool MMU_NOTIFIER Note that direct use of __initcall is discouraged, vs. one of the priority categorized subgroups. As __initcall gets mapped onto device_initcall, our use of subsys_initcall (which makes sense for these files) will thus change this registration from level 6-device to level 4-subsys (i.e. slightly earlier). However no observable impact of that difference has been observed during testing. One might think that core_initcall (l2) or postcore_initcall (l3) would be more appropriate for anything in mm/ but if we look at some actual init functions themselves, we see things like: mm/huge_memory.c --> hugepage_init --> hugepage_init_sysfs mm/mmap.c --> init_user_reserve --> sysctl_user_reserve_kbytes mm/ksm.c --> ksm_init --> sysfs_create_group and hence the choice of subsys_initcall (l4) seems reasonable, and at the same time minimizes the risk of changing the priority too drastically all at once. We can adjust further in the future. Also, several instances of missing ";" at EOL are fixed. Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent da29bd3 commit a64fb3c

4 files changed

Lines changed: 6 additions & 7 deletions

File tree

‎mm/huge_memory.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ static int __init hugepage_init(void)
661661
hugepage_exit_sysfs(hugepage_kobj);
662662
return err;
663663
}
664-
module_init(hugepage_init)
664+
subsys_initcall(hugepage_init);
665665

666666
static int __init setup_transparent_hugepage(char *str)
667667
{

‎mm/ksm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,4 +2345,4 @@ static int __init ksm_init(void)
23452345
out:
23462346
return err;
23472347
}
2348-
module_init(ksm_init)
2348+
subsys_initcall(ksm_init);

‎mm/mmap.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3142,7 +3142,7 @@ static int init_user_reserve(void)
31423142
sysctl_user_reserve_kbytes = min(free_kbytes / 32, 1UL << 17);
31433143
return 0;
31443144
}
3145-
module_init(init_user_reserve)
3145+
subsys_initcall(init_user_reserve);
31463146

31473147
/*
31483148
* Initialise sysctl_admin_reserve_kbytes.
@@ -3163,7 +3163,7 @@ static int init_admin_reserve(void)
31633163
sysctl_admin_reserve_kbytes = min(free_kbytes / 32, 1UL << 13);
31643164
return 0;
31653165
}
3166-
module_init(init_admin_reserve)
3166+
subsys_initcall(init_admin_reserve);
31673167

31683168
/*
31693169
* Reinititalise user and admin reserves if memory is added or removed.
@@ -3233,4 +3233,4 @@ static int __meminit init_reserve_notifier(void)
32333233

32343234
return 0;
32353235
}
3236-
module_init(init_reserve_notifier)
3236+
subsys_initcall(init_reserve_notifier);

‎mm/mmu_notifier.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,4 @@ static int __init mmu_notifier_init(void)
329329
{
330330
return init_srcu_struct(&srcu);
331331
}
332-
333-
module_init(mmu_notifier_init);
332+
subsys_initcall(mmu_notifier_init);

0 commit comments

Comments
 (0)