From f07a3c04e755673facc1f9b45d86cbe6c9b036bc Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 5 Jun 2010 11:17:36 -0600 Subject: [PATCH] --- yaml --- r: 200126 b: refs/heads/master c: 3bafeb6247042dcbb72b0141ec7c7107de9f0b99 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/kernel/module.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index abff834162cc..23ecaf3d01ae 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 75676500f8298f0ee89db12db97294883c4b768e +refs/heads/master: 3bafeb6247042dcbb72b0141ec7c7107de9f0b99 diff --git a/trunk/kernel/module.c b/trunk/kernel/module.c index d293c213c22c..28450047852a 100644 --- a/trunk/kernel/module.c +++ b/trunk/kernel/module.c @@ -2226,11 +2226,6 @@ static noinline struct module *load_module(void __user *umod, goto free_mod; } - if (find_module(mod->name)) { - err = -EEXIST; - goto free_mod; - } - mod->state = MODULE_STATE_COMING; /* Allow arches to frob section contents and sizes. */ @@ -2509,6 +2504,12 @@ static noinline struct module *load_module(void __user *umod, * The mutex protects against concurrent writers. */ mutex_lock(&module_mutex); + if (find_module(mod->name)) { + err = -EEXIST; + /* This will also unlock the mutex */ + goto already_exists; + } + list_add_rcu(&mod->list, &modules); mutex_unlock(&module_mutex); @@ -2535,6 +2536,7 @@ static noinline struct module *load_module(void __user *umod, mutex_lock(&module_mutex); /* Unlink carefully: kallsyms could be walking list. */ list_del_rcu(&mod->list); + already_exists: mutex_unlock(&module_mutex); synchronize_sched(); module_arch_cleanup(mod);