Skip to content

Commit a6e6abd

Browse files
committed
module: remove module_text_address()
Impact: Replace and remove risky (non-EXPORTed) API module_text_address() returns a pointer to the module, which given locking improvements in module.c, is useless except to test for NULL: 1) If the module can't go away, use __module_text_address. 2) Otherwise, just use is_module_text_address(). Cc: linux-mtd@lists.infradead.org Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent e610499 commit a6e6abd

4 files changed

Lines changed: 9 additions & 25 deletions

File tree

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,14 +2720,14 @@ int nand_scan_tail(struct mtd_info *mtd)
27202720
return chip->scan_bbt(mtd);
27212721
}
27222722

2723-
/* module_text_address() isn't exported, and it's mostly a pointless
2723+
/* is_module_text_address() isn't exported, and it's mostly a pointless
27242724
test if this is a module _anyway_ -- they'd have to try _really_ hard
27252725
to call us from in-kernel code if the core NAND support is modular. */
27262726
#ifdef MODULE
27272727
#define caller_is_module() (1)
27282728
#else
27292729
#define caller_is_module() \
2730-
module_text_address((unsigned long)__builtin_return_address(0))
2730+
is_module_text_address((unsigned long)__builtin_return_address(0))
27312731
#endif
27322732

27332733
/**

‎include/linux/module.h‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,6 @@ static inline int module_is_live(struct module *mod)
362362
return mod->state != MODULE_STATE_GOING;
363363
}
364364

365-
/* Is this address in a module? (second is with no locks, for oops) */
366-
struct module *module_text_address(unsigned long addr);
367365
struct module *__module_text_address(unsigned long addr);
368366
struct module *__module_address(unsigned long addr);
369367
bool is_module_address(unsigned long addr);
@@ -496,11 +494,6 @@ search_module_extables(unsigned long addr)
496494
return NULL;
497495
}
498496

499-
static inline struct module *module_text_address(unsigned long addr)
500-
{
501-
return NULL;
502-
}
503-
504497
static inline struct module *__module_address(unsigned long addr)
505498
{
506499
return NULL;

‎kernel/extable.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ __notrace_funcgraph int __kernel_text_address(unsigned long addr)
5858
{
5959
if (core_kernel_text(addr))
6060
return 1;
61-
return __module_text_address(addr) != NULL;
61+
return is_module_text_address(addr);
6262
}
6363

6464
int kernel_text_address(unsigned long addr)
6565
{
6666
if (core_kernel_text(addr))
6767
return 1;
68-
return module_text_address(addr) != NULL;
68+
return is_module_text_address(addr);
6969
}
7070

7171
/*
@@ -81,5 +81,5 @@ int func_ptr_is_kernel_text(void *ptr)
8181
addr = (unsigned long) dereference_function_descriptor(ptr);
8282
if (core_kernel_text(addr))
8383
return 1;
84-
return module_text_address(addr) != NULL;
84+
return is_module_text_address(addr);
8585
}

‎kernel/module.c‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,10 @@ void symbol_put_addr(void *addr)
908908
if (core_kernel_text((unsigned long)addr))
909909
return;
910910

911-
if (!(modaddr = module_text_address((unsigned long)addr)))
912-
BUG();
911+
/* module_text_address is safe here: we're supposed to have reference
912+
* to module from symbol_get, so it can't go away. */
913+
modaddr = __module_text_address((unsigned long)addr);
914+
BUG_ON(!modaddr);
913915
module_put(modaddr);
914916
}
915917
EXPORT_SYMBOL_GPL(symbol_put_addr);
@@ -2821,17 +2823,6 @@ struct module *__module_text_address(unsigned long addr)
28212823
return mod;
28222824
}
28232825

2824-
struct module *module_text_address(unsigned long addr)
2825-
{
2826-
struct module *mod;
2827-
2828-
preempt_disable();
2829-
mod = __module_text_address(addr);
2830-
preempt_enable();
2831-
2832-
return mod;
2833-
}
2834-
28352826
/* Don't grab lock, we're oopsing. */
28362827
void print_modules(void)
28372828
{

0 commit comments

Comments
 (0)