Commit 72ea6af5 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] module_text_address returns the module pointer

By making module_text_address return the module it found, we
simplify symbol_put_addr significantly.
parent 2199860c
...@@ -268,7 +268,7 @@ static inline int module_is_live(struct module *mod) ...@@ -268,7 +268,7 @@ static inline int module_is_live(struct module *mod)
} }
/* Is this address in a module? */ /* Is this address in a module? */
int module_text_address(unsigned long addr); struct module *module_text_address(unsigned long addr);
#ifdef CONFIG_MODULE_UNLOAD #ifdef CONFIG_MODULE_UNLOAD
...@@ -361,9 +361,9 @@ search_module_extables(unsigned long addr) ...@@ -361,9 +361,9 @@ search_module_extables(unsigned long addr)
} }
/* Is this address in a module? */ /* Is this address in a module? */
static inline int module_text_address(unsigned long addr) static inline struct module *module_text_address(unsigned long addr)
{ {
return 0; return NULL;
} }
/* Get/put a kernel symbol (calls should be symmetric) */ /* Get/put a kernel symbol (calls should be symmetric) */
......
...@@ -38,5 +38,5 @@ int kernel_text_address(unsigned long addr) ...@@ -38,5 +38,5 @@ int kernel_text_address(unsigned long addr)
addr <= (unsigned long)_etext) addr <= (unsigned long)_etext)
return 1; return 1;
return module_text_address(addr); return module_text_address(addr) != NULL;
} }
...@@ -552,23 +552,14 @@ EXPORT_SYMBOL(__symbol_put); ...@@ -552,23 +552,14 @@ EXPORT_SYMBOL(__symbol_put);
void symbol_put_addr(void *addr) void symbol_put_addr(void *addr)
{ {
struct kernel_symbol_group *ks;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&modlist_lock, flags); spin_lock_irqsave(&modlist_lock, flags);
list_for_each_entry(ks, &symbols, list) { if (!kernel_text_address((unsigned long)addr))
unsigned int i; BUG();
for (i = 0; i < ks->num_syms; i++) { module_put(module_text_address((unsigned long)addr));
if (ks->syms[i].value == (unsigned long)addr) {
module_put(ks->owner);
spin_unlock_irqrestore(&modlist_lock, flags);
return;
}
}
}
spin_unlock_irqrestore(&modlist_lock, flags); spin_unlock_irqrestore(&modlist_lock, flags);
BUG();
} }
EXPORT_SYMBOL_GPL(symbol_put_addr); EXPORT_SYMBOL_GPL(symbol_put_addr);
...@@ -1545,15 +1536,15 @@ const struct exception_table_entry *search_module_extables(unsigned long addr) ...@@ -1545,15 +1536,15 @@ const struct exception_table_entry *search_module_extables(unsigned long addr)
} }
/* Is this a valid kernel address? We don't grab the lock: we are oopsing. */ /* Is this a valid kernel address? We don't grab the lock: we are oopsing. */
int module_text_address(unsigned long addr) struct module *module_text_address(unsigned long addr)
{ {
struct module *mod; struct module *mod;
list_for_each_entry(mod, &modules, list) list_for_each_entry(mod, &modules, list)
if (within(addr, mod->module_init, mod->init_size) if (within(addr, mod->module_init, mod->init_size)
|| within(addr, mod->module_core, mod->core_size)) || within(addr, mod->module_core, mod->core_size))
return 1; return mod;
return 0; return NULL;
} }
/* Provided by the linker */ /* Provided by the linker */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment