mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-24 15:42:32 +00:00
module: refactor load_module
I'd start from the trivial stuff. There's a fair amount of straight-line code that just makes the function hard to read just because you have to page up and down so far. Some of it is trivial to just create a helper function for. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
2409e74278
commit
f91a13bb99
1 changed files with 69 additions and 61 deletions
128
kernel/module.c
128
kernel/module.c
|
@ -2107,6 +2107,71 @@ static inline void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static void find_module_sections(struct module *mod, Elf_Ehdr *hdr,
|
||||||
|
Elf_Shdr *sechdrs, const char *secstrings)
|
||||||
|
{
|
||||||
|
mod->kp = section_objs(hdr, sechdrs, secstrings, "__param",
|
||||||
|
sizeof(*mod->kp), &mod->num_kp);
|
||||||
|
mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
|
||||||
|
sizeof(*mod->syms), &mod->num_syms);
|
||||||
|
mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
|
||||||
|
mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
|
||||||
|
sizeof(*mod->gpl_syms),
|
||||||
|
&mod->num_gpl_syms);
|
||||||
|
mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
|
||||||
|
mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"__ksymtab_gpl_future",
|
||||||
|
sizeof(*mod->gpl_future_syms),
|
||||||
|
&mod->num_gpl_future_syms);
|
||||||
|
mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
|
||||||
|
"__kcrctab_gpl_future");
|
||||||
|
|
||||||
|
#ifdef CONFIG_UNUSED_SYMBOLS
|
||||||
|
mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"__ksymtab_unused",
|
||||||
|
sizeof(*mod->unused_syms),
|
||||||
|
&mod->num_unused_syms);
|
||||||
|
mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
|
||||||
|
"__kcrctab_unused");
|
||||||
|
mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"__ksymtab_unused_gpl",
|
||||||
|
sizeof(*mod->unused_gpl_syms),
|
||||||
|
&mod->num_unused_gpl_syms);
|
||||||
|
mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
|
||||||
|
"__kcrctab_unused_gpl");
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_CONSTRUCTORS
|
||||||
|
mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors",
|
||||||
|
sizeof(*mod->ctors), &mod->num_ctors);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_TRACEPOINTS
|
||||||
|
mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"__tracepoints",
|
||||||
|
sizeof(*mod->tracepoints),
|
||||||
|
&mod->num_tracepoints);
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_EVENT_TRACING
|
||||||
|
mod->trace_events = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"_ftrace_events",
|
||||||
|
sizeof(*mod->trace_events),
|
||||||
|
&mod->num_trace_events);
|
||||||
|
/*
|
||||||
|
* This section contains pointers to allocated objects in the trace
|
||||||
|
* code and not scanning it leads to false positives.
|
||||||
|
*/
|
||||||
|
kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
|
||||||
|
mod->num_trace_events, GFP_KERNEL);
|
||||||
|
#endif
|
||||||
|
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
|
||||||
|
/* sechdrs[0].sh_size is always zero */
|
||||||
|
mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings,
|
||||||
|
"__mcount_loc",
|
||||||
|
sizeof(*mod->ftrace_callsites),
|
||||||
|
&mod->num_ftrace_callsites);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate and load the module: note that size of section 0 is always
|
/* Allocate and load the module: note that size of section 0 is always
|
||||||
zero, and we rely on this for optional sections. */
|
zero, and we rely on this for optional sections. */
|
||||||
static noinline struct module *load_module(void __user *umod,
|
static noinline struct module *load_module(void __user *umod,
|
||||||
|
@ -2326,7 +2391,8 @@ static noinline struct module *load_module(void __user *umod,
|
||||||
sechdrs[i].sh_size);
|
sechdrs[i].sh_size);
|
||||||
/* Update sh_addr to point to copy in image. */
|
/* Update sh_addr to point to copy in image. */
|
||||||
sechdrs[i].sh_addr = (unsigned long)dest;
|
sechdrs[i].sh_addr = (unsigned long)dest;
|
||||||
DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
|
DEBUGP("\t0x%lx %s\n",
|
||||||
|
sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
|
||||||
}
|
}
|
||||||
/* Module has been moved. */
|
/* Module has been moved. */
|
||||||
mod = (void *)sechdrs[modindex].sh_addr;
|
mod = (void *)sechdrs[modindex].sh_addr;
|
||||||
|
@ -2368,66 +2434,8 @@ static noinline struct module *load_module(void __user *umod,
|
||||||
|
|
||||||
/* Now we've got everything in the final locations, we can
|
/* Now we've got everything in the final locations, we can
|
||||||
* find optional sections. */
|
* find optional sections. */
|
||||||
mod->kp = section_objs(hdr, sechdrs, secstrings, "__param",
|
find_module_sections(mod, hdr, sechdrs, secstrings);
|
||||||
sizeof(*mod->kp), &mod->num_kp);
|
|
||||||
mod->syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab",
|
|
||||||
sizeof(*mod->syms), &mod->num_syms);
|
|
||||||
mod->crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab");
|
|
||||||
mod->gpl_syms = section_objs(hdr, sechdrs, secstrings, "__ksymtab_gpl",
|
|
||||||
sizeof(*mod->gpl_syms),
|
|
||||||
&mod->num_gpl_syms);
|
|
||||||
mod->gpl_crcs = section_addr(hdr, sechdrs, secstrings, "__kcrctab_gpl");
|
|
||||||
mod->gpl_future_syms = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"__ksymtab_gpl_future",
|
|
||||||
sizeof(*mod->gpl_future_syms),
|
|
||||||
&mod->num_gpl_future_syms);
|
|
||||||
mod->gpl_future_crcs = section_addr(hdr, sechdrs, secstrings,
|
|
||||||
"__kcrctab_gpl_future");
|
|
||||||
|
|
||||||
#ifdef CONFIG_UNUSED_SYMBOLS
|
|
||||||
mod->unused_syms = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"__ksymtab_unused",
|
|
||||||
sizeof(*mod->unused_syms),
|
|
||||||
&mod->num_unused_syms);
|
|
||||||
mod->unused_crcs = section_addr(hdr, sechdrs, secstrings,
|
|
||||||
"__kcrctab_unused");
|
|
||||||
mod->unused_gpl_syms = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"__ksymtab_unused_gpl",
|
|
||||||
sizeof(*mod->unused_gpl_syms),
|
|
||||||
&mod->num_unused_gpl_syms);
|
|
||||||
mod->unused_gpl_crcs = section_addr(hdr, sechdrs, secstrings,
|
|
||||||
"__kcrctab_unused_gpl");
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_CONSTRUCTORS
|
|
||||||
mod->ctors = section_objs(hdr, sechdrs, secstrings, ".ctors",
|
|
||||||
sizeof(*mod->ctors), &mod->num_ctors);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_TRACEPOINTS
|
|
||||||
mod->tracepoints = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"__tracepoints",
|
|
||||||
sizeof(*mod->tracepoints),
|
|
||||||
&mod->num_tracepoints);
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_EVENT_TRACING
|
|
||||||
mod->trace_events = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"_ftrace_events",
|
|
||||||
sizeof(*mod->trace_events),
|
|
||||||
&mod->num_trace_events);
|
|
||||||
/*
|
|
||||||
* This section contains pointers to allocated objects in the trace
|
|
||||||
* code and not scanning it leads to false positives.
|
|
||||||
*/
|
|
||||||
kmemleak_scan_area(mod->trace_events, sizeof(*mod->trace_events) *
|
|
||||||
mod->num_trace_events, GFP_KERNEL);
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_FTRACE_MCOUNT_RECORD
|
|
||||||
/* sechdrs[0].sh_size is always zero */
|
|
||||||
mod->ftrace_callsites = section_objs(hdr, sechdrs, secstrings,
|
|
||||||
"__mcount_loc",
|
|
||||||
sizeof(*mod->ftrace_callsites),
|
|
||||||
&mod->num_ftrace_callsites);
|
|
||||||
#endif
|
|
||||||
#ifdef CONFIG_MODVERSIONS
|
#ifdef CONFIG_MODVERSIONS
|
||||||
if ((mod->num_syms && !mod->crcs)
|
if ((mod->num_syms && !mod->crcs)
|
||||||
|| (mod->num_gpl_syms && !mod->gpl_crcs)
|
|| (mod->num_gpl_syms && !mod->gpl_crcs)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue