Skip to content

Commit be1f221

Browse files
committed
module: remove mod arg from module_free, rename module_memfree().
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 <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Cc: Mikael Starvik <[email protected]> Cc: Jesper Nilsson <[email protected]> Cc: Ralf Baechle <[email protected]> Cc: Ley Foon Tan <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Chris Metcalf <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: [email protected] Cc: Ananth N Mavinakayanahalli <[email protected]> Cc: Anil S Keshavamurthy <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
1 parent d453cde commit be1f221

File tree

11 files changed

+18
-18
lines changed

11 files changed

+18
-18
lines changed

arch/cris/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void *module_alloc(unsigned long size)
3636
}
3737

3838
/* Free memory returned from module_alloc */
39-
void module_free(struct module *mod, void *module_region)
39+
void module_memfree(void *module_region)
4040
{
4141
kfree(module_region);
4242
}

arch/mips/net/bpf_jit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
13881388
void bpf_jit_free(struct bpf_prog *fp)
13891389
{
13901390
if (fp->jited)
1391-
module_free(NULL, fp->bpf_func);
1391+
module_memfree(fp->bpf_func);
13921392

13931393
bpf_prog_unlock_free(fp);
13941394
}

arch/nios2/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void *module_alloc(unsigned long size)
3636
}
3737

3838
/* Free memory returned from module_alloc */
39-
void module_free(struct module *mod, void *module_region)
39+
void module_memfree(void *module_region)
4040
{
4141
kfree(module_region);
4242
}

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ void bpf_jit_compile(struct bpf_prog *fp)
699699
void bpf_jit_free(struct bpf_prog *fp)
700700
{
701701
if (fp->jited)
702-
module_free(NULL, fp->bpf_func);
702+
module_memfree(fp->bpf_func);
703703

704704
bpf_prog_unlock_free(fp);
705705
}

arch/sparc/net/bpf_jit_comp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
776776
if (unlikely(proglen + ilen > oldproglen)) {
777777
pr_err("bpb_jit_compile fatal error\n");
778778
kfree(addrs);
779-
module_free(NULL, image);
779+
module_memfree(image);
780780
return;
781781
}
782782
memcpy(image + proglen, temp, ilen);
@@ -822,7 +822,7 @@ cond_branch: f_offset = addrs[i + filter[i].jf];
822822
void bpf_jit_free(struct bpf_prog *fp)
823823
{
824824
if (fp->jited)
825-
module_free(NULL, fp->bpf_func);
825+
module_memfree(fp->bpf_func);
826826

827827
bpf_prog_unlock_free(fp);
828828
}

arch/tile/kernel/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void *module_alloc(unsigned long size)
7474

7575

7676
/* Free memory returned from module_alloc */
77-
void module_free(struct module *mod, void *module_region)
77+
void module_memfree(void *module_region)
7878
{
7979
vfree(module_region);
8080

arch/x86/kernel/ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ static inline void *alloc_tramp(unsigned long size)
674674
}
675675
static inline void tramp_free(void *tramp)
676676
{
677-
module_free(NULL, tramp);
677+
module_memfree(tramp);
678678
}
679679
#else
680680
/* Trampolines can only be created if modules are supported */

include/linux/moduleloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
2626
void *module_alloc(unsigned long size);
2727

2828
/* Free memory returned from module_alloc. */
29-
void module_free(struct module *mod, void *module_region);
29+
void module_memfree(void *module_region);
3030

3131
/*
3232
* Apply the given relocation to the (simplified) ELF. Return -error

kernel/bpf/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
163163

164164
void bpf_jit_binary_free(struct bpf_binary_header *hdr)
165165
{
166-
module_free(NULL, hdr);
166+
module_memfree(hdr);
167167
}
168168
#endif /* CONFIG_BPF_JIT */
169169

kernel/kprobes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static void *alloc_insn_page(void)
127127

128128
static void free_insn_page(void *page)
129129
{
130-
module_free(NULL, page);
130+
module_memfree(page);
131131
}
132132

133133
struct kprobe_insn_cache kprobe_insn_slots = {

kernel/module.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ static void unset_module_core_ro_nx(struct module *mod) { }
17951795
static void unset_module_init_ro_nx(struct module *mod) { }
17961796
#endif
17971797

1798-
void __weak module_free(struct module *mod, void *module_region)
1798+
void __weak module_memfree(void *module_region)
17991799
{
18001800
vfree(module_region);
18011801
}
@@ -1846,7 +1846,7 @@ static void free_module(struct module *mod)
18461846
/* This may be NULL, but that's OK */
18471847
unset_module_init_ro_nx(mod);
18481848
module_arch_freeing_init(mod);
1849-
module_free(mod, mod->module_init);
1849+
module_memfree(mod->module_init);
18501850
kfree(mod->args);
18511851
percpu_modfree(mod);
18521852

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

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

18601860
#ifdef CONFIG_MPU
18611861
update_protections(current->mm);
@@ -2790,7 +2790,7 @@ static int move_module(struct module *mod, struct load_info *info)
27902790
*/
27912791
kmemleak_ignore(ptr);
27922792
if (!ptr) {
2793-
module_free(mod, mod->module_core);
2793+
module_memfree(mod->module_core);
27942794
return -ENOMEM;
27952795
}
27962796
memset(ptr, 0, mod->init_size);
@@ -2936,8 +2936,8 @@ static void module_deallocate(struct module *mod, struct load_info *info)
29362936
{
29372937
percpu_modfree(mod);
29382938
module_arch_freeing_init(mod);
2939-
module_free(mod, mod->module_init);
2940-
module_free(mod, mod->module_core);
2939+
module_memfree(mod->module_init);
2940+
module_memfree(mod->module_core);
29412941
}
29422942

29432943
int __weak module_finalize(const Elf_Ehdr *hdr,
@@ -3062,7 +3062,7 @@ static int do_init_module(struct module *mod)
30623062
#endif
30633063
unset_module_init_ro_nx(mod);
30643064
module_arch_freeing_init(mod);
3065-
module_free(mod, mod->module_init);
3065+
module_memfree(mod->module_init);
30663066
mod->module_init = NULL;
30673067
mod->init_size = 0;
30683068
mod->init_ro_size = 0;

0 commit comments

Comments
 (0)