From: Daniel Gomez <da.gomez@samsung.com>
Ensure the module reference is only dropped once in case we fail at
MOD_RO_AFTER_INIT case.
Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
kernel/module/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/module/main.c b/kernel/module/main.c
index e0b2a8d9e324..35a50ded64a6 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -2941,8 +2941,6 @@ static noinline int do_init_module(struct module *mod)
ftrace_free_mem(mod, mod->mem[MOD_INIT_TEXT].base,
mod->mem[MOD_INIT_TEXT].base + mod->mem[MOD_INIT_TEXT].size);
mutex_lock(&module_mutex);
- /* Drop initial reference. */
- module_put(mod);
trim_init_extable(mod);
#ifdef CONFIG_KALLSYMS
/* Switch to core kallsyms now init is done: kallsyms may be walking! */
@@ -2951,6 +2949,8 @@ static noinline int do_init_module(struct module *mod)
ret = module_enable_rodata_ro(mod, true);
if (ret)
goto fail_mutex_unlock;
+ /* Drop initial reference. */
+ module_put(mod);
mod_tree_remove_init(mod);
module_arch_freeing_init(mod);
for_class_mod_mem_type(type, init) {
--
2.39.2