From: Rusty Russell <rusty@rustcorp.com.au>
To: linux-kernel@vger.kernel.org
Cc: Rusty Russell <rusty@rustcorp.com.au>,
Weilong Chen <chenweilong@huawei.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"PDate:Wed"@ozlabs.org, 3@ozlabs.org, Feb@ozlabs.org,
2016@ozlabs.org, "16:55:26"@ozlabs.org, +1030@ozlabs.org,
stable@kernel.org
Subject: [PATCH 2/3] module: wrapper for symbol name.
Date: Fri, 5 Feb 2016 10:44:12 +1030 [thread overview]
Message-ID: <1454631253-14379-3-git-send-email-rusty@rustcorp.com.au> (raw)
In-Reply-To: <1454631253-14379-1-git-send-email-rusty@rustcorp.com.au>
This trivial wrapper adds clarity and makes the following patch
smaller.
Cc: stable@kernel.org
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
---
kernel/module.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index 2149f7003e49..1e79d8157712 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -3627,6 +3627,11 @@ static inline int is_arm_mapping_symbol(const char *str)
&& (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,
unsigned long addr,
unsigned long *size,
@@ -3649,15 +3654,15 @@ static const char *get_ksymbol(struct module *mod,
/* We ignore unnamed symbols: they're uninformative
* 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
- && 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))
+ && mod->symtab[i].st_value > mod->symtab[best].st_value)
best = i;
if (mod->symtab[i].st_value > addr
- && 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))
+ && mod->symtab[i].st_value < nextval)
nextval = mod->symtab[i].st_value;
}
@@ -3668,7 +3673,7 @@ static const char *get_ksymbol(struct module *mod,
*size = nextval - mod->symtab[best].st_value;
if (offset)
*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
@@ -3763,8 +3768,7 @@ int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
if (symnum < mod->num_symtab) {
*value = mod->symtab[symnum].st_value;
*type = mod->symtab[symnum].st_info;
- strlcpy(name, mod->strtab + mod->symtab[symnum].st_name,
- KSYM_NAME_LEN);
+ strlcpy(name, symname(mod, symnum), KSYM_NAME_LEN);
strlcpy(module_name, mod->name, MODULE_NAME_LEN);
*exported = is_exported(name, *value, mod);
preempt_enable();
@@ -3781,7 +3785,7 @@ static unsigned long mod_find_symname(struct module *mod, const char *name)
unsigned int 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')
return mod->symtab[i].st_value;
return 0;
@@ -3825,7 +3829,7 @@ int module_kallsyms_on_each_symbol(int (*fn)(void *, const char *,
if (mod->state == MODULE_STATE_UNFORMED)
continue;
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);
if (ret != 0)
return ret;
--
2.5.0
next prev parent reply other threads:[~2016-02-05 0:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 0:14 [PATCH 0/3] module stable fixes Rusty Russell
2016-02-05 0:14 ` [PATCH 1/3] modules: fix modparam async_probe request Rusty Russell
2016-02-05 0:14 ` Rusty Russell [this message]
2016-02-05 6:45 ` [PATCH 2/3] module: wrapper for symbol name 平松雅巳 / HIRAMATU,MASAMI
2016-02-05 0:14 ` [PATCH 3/3] modules: fix longstanding /proc/kallsyms vs module insertion race Rusty Russell
2016-02-05 6:41 ` 平松雅巳 / HIRAMATU,MASAMI
2016-02-05 6:51 ` [PATCH 0/3] module stable fixes 平松雅巳 / HIRAMATU,MASAMI
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454631253-14379-3-git-send-email-rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc="16:55:26"@ozlabs.org \
--cc="PDate:Wed"@ozlabs.org \
--cc=+1030@ozlabs.org \
--cc=2016@ozlabs.org \
--cc=3@ozlabs.org \
--cc=Feb@ozlabs.org \
--cc=chenweilong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=stable@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®