Skip to content

Commit 2e7bac5

Browse files
committed
module: wrapper for symbol name.
This trivial wrapper adds clarity and makes the following patch smaller. Cc: stable@kernel.org Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 4355efb commit 2e7bac5

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

‎kernel/module.c‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,6 +3627,11 @@ static inline int is_arm_mapping_symbol(const char *str)
36273627
&& (str[2] == '\0' || str[2] == '.');
36283628
}
36293629

3630+
static const char *symname(struct module *mod, unsigned int symnum)
3631+
{
3632+
return mod->strtab + mod->symtab[symnum].st_name;
3633+
}
3634+
36303635
static const char *get_ksymbol(struct module *mod,
36313636
unsigned long addr,
36323637
unsigned long *size,
@@ -3649,15 +3654,15 @@ static const char *get_ksymbol(struct module *mod,
36493654

36503655
/* We ignore unnamed symbols: they're uninformative
36513656
* and inserted at a whim. */
3657+
if (*symname(mod, i) == '\0'
3658+
|| is_arm_mapping_symbol(symname(mod, i)))
3659+
continue;
3660+
36523661
if (mod->symtab[i].st_value <= addr
3653-
&& mod->symtab[i].st_value > mod->symtab[best].st_value
3654-
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
3655-
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3662+
&& mod->symtab[i].st_value > mod->symtab[best].st_value)
36563663
best = i;
36573664
if (mod->symtab[i].st_value > addr
3658-
&& mod->symtab[i].st_value < nextval
3659-
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
3660-
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3665+
&& mod->symtab[i].st_value < nextval)
36613666
nextval = mod->symtab[i].st_value;
36623667
}
36633668

@@ -3668,7 +3673,7 @@ static const char *get_ksymbol(struct module *mod,
36683673
*size = nextval - mod->symtab[best].st_value;
36693674
if (offset)
36703675
*offset = addr - mod->symtab[best].st_value;
3671-
return mod->strtab + mod->symtab[best].st_name;
3676+
return symname(mod, best);
36723677
}
36733678

36743679
/* For kallsyms to ask for address resolution. NULL means not found. Careful
@@ -3763,8 +3768,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
37633768
if (symnum < mod->num_symtab) {
37643769
*value = mod->symtab[symnum].st_value;
37653770
*type = mod->symtab[symnum].st_info;
3766-
strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
3767-
KSYM_NAME_LEN);
3771+
strlcpy(name, symname(mod, symnum), KSYM_NAME_LEN);
37683772
strlcpy(module_name, mod->name, MODULE_NAME_LEN);
37693773
*exported = is_exported(name, *value, mod);
37703774
preempt_enable();
@@ -3781,7 +3785,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
37813785
unsigned int i;
37823786

37833787
for (i = 0; i < mod->num_symtab; i++)
3784-
if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
3788+
if (strcmp(name, symname(mod, i)) == 0 &&
37853789
mod->symtab[i].st_info != 'U')
37863790
return mod->symtab[i].st_value;
37873791
return 0;
@@ -3825,7 +3829,7 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
38253829
if (mod->state == MODULE_STATE_UNFORMED)
38263830
continue;
38273831
for (i = 0; i < mod->num_symtab; i++) {
3828-
ret = fn(data, mod->strtab + mod->symtab[i].st_name,
3832+
ret = fn(data, symname(mod, i),
38293833
mod, mod->symtab[i].st_value);
38303834
if (ret != 0)
38313835
return ret;

0 commit comments

Comments
 (0)