/* We leave it in list to prevent duplicate loads, but make sure
* that noone uses it while it's being deconstructed. */
- mutex_lock(&module_mutex);
mod->state = MODULE_STATE_UNFORMED;
- mutex_unlock(&module_mutex);
/* Remove dynamic debug info */
ddebug_remove_module(mod->name);
{
/* Module within temporary copy. */
struct module *mod;
+ Elf_Shdr *pcpusec;
int err;
mod = setup_load_info(info, flags);
err = module_frob_arch_sections(info->hdr, info->sechdrs,
info->secstrings, mod);
if (err < 0)
- return ERR_PTR(err);
+ goto out;
- /* We will do a special allocation for per-cpu sections later. */
- info->sechdrs[info->index.pcpu].sh_flags &= ~(unsigned long)SHF_ALLOC;
+ pcpusec = &info->sechdrs[info->index.pcpu];
+ if (pcpusec->sh_size) {
+ /* We have a special allocation for this section. */
+ err = percpu_modalloc(mod,
+ pcpusec->sh_size, pcpusec->sh_addralign);
+ if (err)
+ goto out;
+ pcpusec->sh_flags &= ~(unsigned long)SHF_ALLOC;
+ }
/* Determine total sizes, and put offsets in sh_entsize. For now
this is done generically; there doesn't appear to be any
/* Allocate and move to the final place */
err = move_module(mod, info);
if (err)
- return ERR_PTR(err);
+ goto free_percpu;
/* Module has been copied to its final place now: return it. */
mod = (void *)info->sechdrs[info->index.mod].sh_addr;
kmemleak_load_module(mod, info);
return mod;
-}
-static int alloc_module_percpu(struct module *mod, struct load_info *info)
-{
- Elf_Shdr *pcpusec = &info->sechdrs[info->index.pcpu];
- if (!pcpusec->sh_size)
- return 0;
-
- /* We have a special allocation for this section. */
- return percpu_modalloc(mod, pcpusec->sh_size, pcpusec->sh_addralign);
+free_percpu:
+ percpu_modfree(mod);
+out:
+ return ERR_PTR(err);
}
/* mod is no longer valid after this! */
}
#endif
- /* To avoid stressing percpu allocator, do this once we're unique. */
- err = alloc_module_percpu(mod, info);
- if (err)
- goto unlink_mod;
-
/* Now module is in final location, initialize linked lists, etc. */
err = module_unload_init(mod);
if (err)
dynamic_debug_setup(info->debug, info->num_debug);
- /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
- ftrace_module_init(mod);
-
/* Finally it's fully formed, ready to start executing. */
err = complete_formation(mod, info);
if (err)