Skip to content

Commit 4c973d1

Browse files
Jessica YuJiri Kosina
authored andcommitted
modules: split part of complete_formation() into prepare_coming_module()
Put all actions in complete_formation() that are performed after module->state is set to MODULE_STATE_COMING into a separate function prepare_coming_module(). This split prepares for the removal of the livepatch module notifiers in favor of hard-coding function calls to klp_module_{coming,going} in the module loader. The complete_formation -> prepare_coming_module split will also make error handling easier since we can jump to the appropriate error label to do any module GOING cleanup after all the COMING-actions have completed. Signed-off-by: Jessica Yu <[email protected]> Reviewed-by: Josh Poimboeuf <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: Rusty Russell <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 06e1c17 commit 4c973d1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

kernel/module.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,16 +3392,21 @@ static int complete_formation(struct module *mod, struct load_info *info)
33923392
mod->state = MODULE_STATE_COMING;
33933393
mutex_unlock(&module_mutex);
33943394

3395-
ftrace_module_enable(mod);
3396-
blocking_notifier_call_chain(&module_notify_list,
3397-
MODULE_STATE_COMING, mod);
33983395
return 0;
33993396

34003397
out:
34013398
mutex_unlock(&module_mutex);
34023399
return err;
34033400
}
34043401

3402+
static int prepare_coming_module(struct module *mod)
3403+
{
3404+
ftrace_module_enable(mod);
3405+
blocking_notifier_call_chain(&module_notify_list,
3406+
MODULE_STATE_COMING, mod);
3407+
return 0;
3408+
}
3409+
34053410
static int unknown_module_param_cb(char *param, char *val, const char *modname,
34063411
void *arg)
34073412
{
@@ -3516,13 +3521,17 @@ static int load_module(struct load_info *info, const char __user *uargs,
35163521
if (err)
35173522
goto ddebug_cleanup;
35183523

3524+
err = prepare_coming_module(mod);
3525+
if (err)
3526+
goto bug_cleanup;
3527+
35193528
/* Module is ready to execute: parsing args may do that. */
35203529
after_dashes = parse_args(mod->name, mod->args, mod->kp, mod->num_kp,
35213530
-32768, 32767, mod,
35223531
unknown_module_param_cb);
35233532
if (IS_ERR(after_dashes)) {
35243533
err = PTR_ERR(after_dashes);
3525-
goto bug_cleanup;
3534+
goto coming_cleanup;
35263535
} else if (after_dashes) {
35273536
pr_warn("%s: parameters '%s' after `--' ignored\n",
35283537
mod->name, after_dashes);
@@ -3531,7 +3540,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
35313540
/* Link in to syfs. */
35323541
err = mod_sysfs_setup(mod, info, mod->kp, mod->num_kp);
35333542
if (err < 0)
3534-
goto bug_cleanup;
3543+
goto coming_cleanup;
35353544

35363545
/* Get rid of temporary copy. */
35373546
free_copy(info);
@@ -3541,15 +3550,16 @@ static int load_module(struct load_info *info, const char __user *uargs,
35413550

35423551
return do_init_module(mod);
35433552

3553+
coming_cleanup:
3554+
blocking_notifier_call_chain(&module_notify_list,
3555+
MODULE_STATE_GOING, mod);
3556+
35443557
bug_cleanup:
35453558
/* module_bug_cleanup needs module_mutex protection */
35463559
mutex_lock(&module_mutex);
35473560
module_bug_cleanup(mod);
35483561
mutex_unlock(&module_mutex);
35493562

3550-
blocking_notifier_call_chain(&module_notify_list,
3551-
MODULE_STATE_GOING, mod);
3552-
35533563
/* we can't deallocate the module until we clear memory protection */
35543564
module_disable_ro(mod);
35553565
module_disable_nx(mod);

0 commit comments

Comments
 (0)