[PATCH 2/2] init/main.c: sink the kernel_init to the bottom

From: Liu Peibao
Date: Wed Dec 30 2020 - 01:25:36 EST


Remove the redundant kernel_init_freeable statement.

Signed-off-by: Liu Peibao <liupeibao@xxxxxxx>
---
init/main.c | 132 ++++++++++++++++++++++++++--------------------------
1 file changed, 65 insertions(+), 67 deletions(-)

diff --git a/init/main.c b/init/main.c
index 1e492de770c8..d5c2fa85ee54 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1364,8 +1364,6 @@ static int try_to_run_init_process(const char *init_filename)
return ret;
}

-static noinline void __init kernel_init_freeable(void);
-
#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX)
bool rodata_enabled __ro_after_init = true;
static int __init set_debug_rodata(char *str)
@@ -1408,71 +1406,6 @@ void __weak free_initmem(void)
free_initmem_default(POISON_FREE_INITMEM);
}

-static int __ref kernel_init(void *unused)
-{
- int ret;
-
- kernel_init_freeable();
- /* need to finish all async __init code before freeing the memory */
- async_synchronize_full();
- kprobe_free_init_mem();
- ftrace_free_init_mem();
- free_initmem();
- mark_readonly();
-
- /*
- * Kernel mappings are now finalized - update the userspace page-table
- * to finalize PTI.
- */
- pti_finalize();
-
- system_state = SYSTEM_RUNNING;
- numa_default_policy();
-
- rcu_end_inkernel_boot();
-
- do_sysctl_args();
-
- if (ramdisk_execute_command) {
- ret = run_init_process(ramdisk_execute_command);
- if (!ret)
- return 0;
- pr_err("Failed to execute %s (error %d)\n",
- ramdisk_execute_command, ret);
- }
-
- /*
- * We try each of these until one succeeds.
- *
- * The Bourne shell can be used instead of init if we are
- * trying to recover a really broken machine.
- */
- if (execute_command) {
- ret = run_init_process(execute_command);
- if (!ret)
- return 0;
- panic("Requested init %s failed (error %d).",
- execute_command, ret);
- }
-
- if (CONFIG_DEFAULT_INIT[0] != '\0') {
- ret = run_init_process(CONFIG_DEFAULT_INIT);
- if (ret)
- pr_err("Default init %s failed (error %d)\n",
- CONFIG_DEFAULT_INIT, ret);
- else
- return 0;
- }
-
- if (!try_to_run_init_process("/sbin/init") ||
- !try_to_run_init_process("/etc/init") ||
- !try_to_run_init_process("/bin/init") ||
- !try_to_run_init_process("/bin/sh"))
- return 0;
-
- panic("No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.");
-}
-
/* Open /dev/console, for stdin/stdout/stderr, this should never fail */
void __init console_on_rootfs(void)
{
@@ -1554,3 +1487,68 @@ static noinline void __init kernel_init_freeable(void)

integrity_load_keys();
}
+
+static int __ref kernel_init(void *unused)
+{
+ int ret;
+
+ kernel_init_freeable();
+ /* need to finish all async __init code before freeing the memory */
+ async_synchronize_full();
+ kprobe_free_init_mem();
+ ftrace_free_init_mem();
+ free_initmem();
+ mark_readonly();
+
+ /*
+ * Kernel mappings are now finalized - update the userspace page-table
+ * to finalize PTI.
+ */
+ pti_finalize();
+
+ system_state = SYSTEM_RUNNING;
+ numa_default_policy();
+
+ rcu_end_inkernel_boot();
+
+ do_sysctl_args();
+
+ if (ramdisk_execute_command) {
+ ret = run_init_process(ramdisk_execute_command);
+ if (!ret)
+ return 0;
+ pr_err("Failed to execute %s (error %d)\n",
+ ramdisk_execute_command, ret);
+ }
+
+ /*
+ * We try each of these until one succeeds.
+ *
+ * The Bourne shell can be used instead of init if we are
+ * trying to recover a really broken machine.
+ */
+ if (execute_command) {
+ ret = run_init_process(execute_command);
+ if (!ret)
+ return 0;
+ panic("Requested init %s failed (error %d).",
+ execute_command, ret);
+ }
+
+ if (CONFIG_DEFAULT_INIT[0] != '\0') {
+ ret = run_init_process(CONFIG_DEFAULT_INIT);
+ if (ret)
+ pr_err("Default init %s failed (error %d)\n",
+ CONFIG_DEFAULT_INIT, ret);
+ else
+ return 0;
+ }
+
+ if (!try_to_run_init_process("/sbin/init") ||
+ !try_to_run_init_process("/etc/init") ||
+ !try_to_run_init_process("/bin/init") ||
+ !try_to_run_init_process("/bin/sh"))
+ return 0;
+
+ panic("No working init found. Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidance.");
+}
--
2.17.1