Skip to content

Commit a24d9a2

Browse files
rustyrussellgregkh
authored andcommitted
module: wrapper for symbol name.
commit 2e7bac536106236104e9e339531ff0fcdb7b8147 upstream. This trivial wrapper adds clarity and makes the following patch smaller. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 82e730b commit a24d9a2

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
@@ -3646,6 +3646,11 @@ static inline int is_arm_mapping_symbol(const char *str)
36463646
&& (str[2] == '\0' || str[2] == '.');
36473647
}
36483648

3649+
static const char *symname(struct module *mod, unsigned int symnum)
3650+
{
3651+
return mod->strtab + mod->symtab[symnum].st_name;
3652+
}
3653+
36493654
static const char *get_ksymbol(struct module *mod,
36503655
unsigned long addr,
36513656
unsigned long *size,
@@ -3668,15 +3673,15 @@ static const char *get_ksymbol(struct module *mod,
36683673

36693674
/* We ignore unnamed symbols: they're uninformative
36703675
* and inserted at a whim. */
3676+
if (*symname(mod, i) == '\0'
3677+
|| is_arm_mapping_symbol(symname(mod, i)))
3678+
continue;
3679+
36713680
if (mod->symtab[i].st_value <= addr
3672-
&& mod->symtab[i].st_value > mod->symtab[best].st_value
3673-
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
3674-
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3681+
&& mod->symtab[i].st_value > mod->symtab[best].st_value)
36753682
best = i;
36763683
if (mod->symtab[i].st_value > addr
3677-
&& mod->symtab[i].st_value < nextval
3678-
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
3679-
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
3684+
&& mod->symtab[i].st_value < nextval)
36803685
nextval = mod->symtab[i].st_value;
36813686
}
36823687

@@ -3687,7 +3692,7 @@ static const char *get_ksymbol(struct module *mod,
36873692
*size = nextval - mod->symtab[best].st_value;
36883693
if (offset)
36893694
*offset = addr - mod->symtab[best].st_value;
3690-
return mod->strtab + mod->symtab[best].st_name;
3695+
return symname(mod, best);
36913696
}
36923697

36933698
/* For kallsyms to ask for address resolution. NULL means not found. Careful
@@ -3782,8 +3787,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
37823787
if (symnum < mod->num_symtab) {
37833788
*value = mod->symtab[symnum].st_value;
37843789
*type = mod->symtab[symnum].st_info;
3785-
strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
3786-
KSYM_NAME_LEN);
3790+
strlcpy(name, symname(mod, symnum), KSYM_NAME_LEN);
37873791
strlcpy(module_name, mod->name, MODULE_NAME_LEN);
37883792
*exported = is_exported(name, *value, mod);
37893793
preempt_enable();
@@ -3800,7 +3804,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
38003804
unsigned int i;
38013805

38023806
for (i = 0; i < mod->num_symtab; i++)
3803-
if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 &&
3807+
if (strcmp(name, symname(mod, i)) == 0 &&
38043808
mod->symtab[i].st_info != 'U')
38053809
return mod->symtab[i].st_value;
38063810
return 0;
@@ -3844,7 +3848,7 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
38443848
if (mod->state == MODULE_STATE_UNFORMED)
38453849
continue;
38463850
for (i = 0; i < mod->num_symtab; i++) {
3847-
ret = fn(data, mod->strtab + mod->symtab[i].st_name,
3851+
ret = fn(data, symname(mod, i),
38483852
mod, mod->symtab[i].st_value);
38493853
if (ret != 0)
38503854
return ret;

0 commit comments

Comments
 (0)