Skip to content

Commit

Permalink
module: add within_module() function
Browse files Browse the repository at this point in the history
It is just a small optimization that allows to replace few
occurrences of within_module_init() || within_module_core()
with a single call.

Signed-off-by: Petr Mladek <pmladek@suse.cz>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Petr Mladek authored and Rusty Russell committed Jul 27, 2014
1 parent 3a611c3 commit 9b20a35
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions include/linux/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,11 @@ static inline int within_module_init(unsigned long addr, const struct module *mo
addr < (unsigned long)mod->module_init + mod->init_size;
}

static inline int within_module(unsigned long addr, const struct module *mod)
{
return within_module_init(addr, mod) || within_module_core(addr, mod);
}

/* Search for module by name: must hold module_mutex. */
struct module *find_module(const char *name);

Expand Down
12 changes: 4 additions & 8 deletions kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -3448,8 +3448,7 @@ const char *module_address_lookup(unsigned long addr,
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (within_module_init(addr, mod) ||
within_module_core(addr, mod)) {
if (within_module(addr, mod)) {
if (modname)
*modname = mod->name;
ret = get_ksymbol(mod, addr, size, offset);
Expand All @@ -3473,8 +3472,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname)
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (within_module_init(addr, mod) ||
within_module_core(addr, mod)) {
if (within_module(addr, mod)) {
const char *sym;

sym = get_ksymbol(mod, addr, NULL, NULL);
Expand All @@ -3499,8 +3497,7 @@ int lookup_module_symbol_attrs(unsigned long addr, unsigned long *size,
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (within_module_init(addr, mod) ||
within_module_core(addr, mod)) {
if (within_module(addr, mod)) {
const char *sym;

sym = get_ksymbol(mod, addr, size, offset);
Expand Down Expand Up @@ -3764,8 +3761,7 @@ struct module *__module_address(unsigned long addr)
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
if (within_module_core(addr, mod)
|| within_module_init(addr, mod))
if (within_module(addr, mod))
return mod;
}
return NULL;
Expand Down

0 comments on commit 9b20a35

Please sign in to comment.