Skip to content

Commit

Permalink
module: remove mod arg from module_free, rename module_memfree().
Browse files Browse the repository at this point in the history
Nothing needs the module pointer any more, and the next patch will
call it from RCU, where the module itself might no longer exist.
Removing the arg is the safest approach.

This just codifies the use of the module_alloc/module_free pattern
which ftrace and bpf use.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Mikael Starvik <starvik@axis.com>
Cc: Jesper Nilsson <jesper.nilsson@axis.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: x86@kernel.org
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: linux-cris-kernel@axis.com
Cc: linux-kernel@vger.kernel.org
Cc: linux-mips@linux-mips.org
Cc: nios2-dev@lists.rocketboards.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: sparclinux@vger.kernel.org
Cc: netdev@vger.kernel.org
  • Loading branch information
Rusty Russell committed Jan 20, 2015
1 parent d453cde commit be1f221
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion arch/cris/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void *module_alloc(unsigned long size)
}

/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
void module_memfree(void *module_region)
{
kfree(module_region);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/net/bpf_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
module_memfree(fp->bpf_func);

bpf_prog_unlock_free(fp);
}
2 changes: 1 addition & 1 deletion arch/nios2/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void *module_alloc(unsigned long size)
}

/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
void module_memfree(void *module_region)
{
kfree(module_region);
}
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
module_memfree(fp->bpf_func);

bpf_prog_unlock_free(fp);
}
4 changes: 2 additions & 2 deletions arch/sparc/net/bpf_jit_comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
if (unlikely(proglen + ilen > oldproglen)) {
pr_err("bpb_jit_compile fatal error\n");
kfree(addrs);
module_free(NULL, image);
module_memfree(image);
return;
}
memcpy(image + proglen, temp, ilen);
Expand Down Expand Up @@ -822,7 +822,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
void bpf_jit_free(struct bpf_prog *fp)
{
if (fp->jited)
module_free(NULL, fp->bpf_func);
module_memfree(fp->bpf_func);

bpf_prog_unlock_free(fp);
}
2 changes: 1 addition & 1 deletion arch/tile/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void *module_alloc(unsigned long size)


/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
void module_memfree(void *module_region)
{
vfree(module_region);

Expand Down
2 changes: 1 addition & 1 deletion arch/x86/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ static inline void *alloc_tramp(unsigned long size)
}
static inline void tramp_free(void *tramp)
{
module_free(NULL, tramp);
module_memfree(tramp);
}
#else
/* Trampolines can only be created if modules are supported */
Expand Down
2 changes: 1 addition & 1 deletion include/linux/moduleloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
void *module_alloc(unsigned long size);

/* Free memory returned from module_alloc. */
void module_free(struct module *mod, void *module_region);
void module_memfree(void *module_region);

/*
* Apply the given relocation to the (simplified) ELF. Return -error
Expand Down
2 changes: 1 addition & 1 deletion kernel/bpf/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,

void bpf_jit_binary_free(struct bpf_binary_header *hdr)
{
module_free(NULL, hdr);
module_memfree(hdr);
}
#endif /* CONFIG_BPF_JIT */

Expand Down
2 changes: 1 addition & 1 deletion kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ static void *alloc_insn_page(void)

static void free_insn_page(void *page)
{
module_free(NULL, page);
module_memfree(page);
}

struct kprobe_insn_cache kprobe_insn_slots = {
Expand Down
14 changes: 7 additions & 7 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ static void unset_module_core_ro_nx(struct module *mod) { }
static void unset_module_init_ro_nx(struct module *mod) { }
#endif

void __weak module_free(struct module *mod, void *module_region)
void __weak module_memfree(void *module_region)
{
vfree(module_region);
}
Expand Down Expand Up @@ -1846,7 +1846,7 @@ static void free_module(struct module *mod)
/* This may be NULL, but that's OK */
unset_module_init_ro_nx(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
module_memfree(mod->module_init);
kfree(mod->args);
percpu_modfree(mod);

Expand All @@ -1855,7 +1855,7 @@ static void free_module(struct module *mod)

/* Finally, free the core (containing the module structure) */
unset_module_core_ro_nx(mod);
module_free(mod, mod->module_core);
module_memfree(mod->module_core);

#ifdef CONFIG_MPU
update_protections(current->mm);
Expand Down Expand Up @@ -2790,7 +2790,7 @@ static int move_module(struct module *mod, struct load_info *info)
*/
kmemleak_ignore(ptr);
if (!ptr) {
module_free(mod, mod->module_core);
module_memfree(mod->module_core);
return -ENOMEM;
}
memset(ptr, 0, mod->init_size);
Expand Down Expand Up @@ -2936,8 +2936,8 @@ static void module_deallocate(struct module *mod, struct load_info *info)
{
percpu_modfree(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
module_free(mod, mod->module_core);
module_memfree(mod->module_init);
module_memfree(mod->module_core);
}

int __weak module_finalize(const Elf_Ehdr *hdr,
Expand Down Expand Up @@ -3062,7 +3062,7 @@ static int do_init_module(struct module *mod)
#endif
unset_module_init_ro_nx(mod);
module_arch_freeing_init(mod);
module_free(mod, mod->module_init);
module_memfree(mod->module_init);
mod->module_init = NULL;
mod->init_size = 0;
mod->init_ro_size = 0;
Expand Down

0 comments on commit be1f221

Please sign in to comment.