Commit 99cdf12b authored by Rusty Russell's avatar Rusty Russell Committed by Sasha Levin

module: wrapper for symbol name.

[ Upstream commit 2e7bac53 ]

This trivial wrapper adds clarity and makes the following patch
smaller.

Cc: stable@kernel.org
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
parent 983cabe4
...@@ -3401,6 +3401,11 @@ static inline int is_arm_mapping_symbol(const char *str) ...@@ -3401,6 +3401,11 @@ static inline int is_arm_mapping_symbol(const char *str)
&& (str[2] == '\0' || str[2] == '.'); && (str[2] == '\0' || str[2] == '.');
} }
static const char *symname(struct module *mod, unsigned int symnum)
{
return mod->strtab + mod->symtab[symnum].st_name;
}
static const char *get_ksymbol(struct module *mod, static const char *get_ksymbol(struct module *mod,
unsigned long addr, unsigned long addr,
unsigned long *size, unsigned long *size,
...@@ -3423,15 +3428,15 @@ static const char *get_ksymbol(struct module *mod, ...@@ -3423,15 +3428,15 @@ static const char *get_ksymbol(struct module *mod,
/* We ignore unnamed symbols: they're uninformative /* We ignore unnamed symbols: they're uninformative
* and inserted at a whim. */ * and inserted at a whim. */
if (*symname(mod, i) == '\0'
|| is_arm_mapping_symbol(symname(mod, i)))
continue;
if (mod->symtab[i].st_value <= addr if (mod->symtab[i].st_value <= addr
&& mod->symtab[i].st_value > mod->symtab[best].st_value && mod->symtab[i].st_value > mod->symtab[best].st_value)
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
best = i; best = i;
if (mod->symtab[i].st_value > addr if (mod->symtab[i].st_value > addr
&& mod->symtab[i].st_value < nextval && mod->symtab[i].st_value < nextval)
&& *(mod->strtab + mod->symtab[i].st_name) != '\0'
&& !is_arm_mapping_symbol(mod->strtab + mod->symtab[i].st_name))
nextval = mod->symtab[i].st_value; nextval = mod->symtab[i].st_value;
} }
...@@ -3442,7 +3447,7 @@ static const char *get_ksymbol(struct module *mod, ...@@ -3442,7 +3447,7 @@ static const char *get_ksymbol(struct module *mod,
*size = nextval - mod->symtab[best].st_value; *size = nextval - mod->symtab[best].st_value;
if (offset) if (offset)
*offset = addr - mod->symtab[best].st_value; *offset = addr - mod->symtab[best].st_value;
return mod->strtab + mod->symtab[best].st_name; return symname(mod, best);
} }
/* For kallsyms to ask for address resolution. NULL means not found. Careful /* For kallsyms to ask for address resolution. NULL means not found. Careful
...@@ -3540,8 +3545,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type, ...@@ -3540,8 +3545,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
if (symnum < mod->num_symtab) { if (symnum < mod->num_symtab) {
*value = mod->symtab[symnum].st_value; *value = mod->symtab[symnum].st_value;
*type = mod->symtab[symnum].st_info; *type = mod->symtab[symnum].st_info;
strlcpy(name, mod->strtab + mod->symtab[symnum].st_name, strlcpy(name, symname(mod, symnum), KSYM_NAME_LEN);
KSYM_NAME_LEN);
strlcpy(module_name, mod->name, MODULE_NAME_LEN); strlcpy(module_name, mod->name, MODULE_NAME_LEN);
*exported = is_exported(name, *value, mod); *exported = is_exported(name, *value, mod);
preempt_enable(); preempt_enable();
...@@ -3558,7 +3562,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name) ...@@ -3558,7 +3562,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
unsigned int i; unsigned int i;
for (i = 0; i < mod->num_symtab; i++) for (i = 0; i < mod->num_symtab; i++)
if (strcmp(name, mod->strtab+mod->symtab[i].st_name) == 0 && if (strcmp(name, symname(mod, i)) == 0 &&
mod->symtab[i].st_info != 'U') mod->symtab[i].st_info != 'U')
return mod->symtab[i].st_value; return mod->symtab[i].st_value;
return 0; return 0;
...@@ -3600,7 +3604,7 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *, ...@@ -3600,7 +3604,7 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
if (mod->state == MODULE_STATE_UNFORMED) if (mod->state == MODULE_STATE_UNFORMED)
continue; continue;
for (i = 0; i < mod->num_symtab; i++) { for (i = 0; i < mod->num_symtab; i++) {
ret = fn(data, mod->strtab + mod->symtab[i].st_name, ret = fn(data, symname(mod, i),
mod, mod->symtab[i].st_value); mod, mod->symtab[i].st_value);
if (ret != 0) if (ret != 0)
return ret; return ret;
......
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