From: Chen Gang <gang.chen@asianux.com>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v2] kernel/module.c: cleanup patch for looping, let return 'bool' value instead of real error number.
Date: Mon, 13 May 2013 20:24:20 +0800 [thread overview]
Message-ID: <5190DB74.6050100@asianux.com> (raw)
In-Reply-To: <51905EEF.2050901@asianux.com>
For looping in simplify_symbols(), when multiple errors occur, the
original error number will be override (the original related commit
"1da177e Linux-2.6.12-rc").
We focus on printing all errors as much as possible, and not focus on
the return error number (only know whether succeed or not is enough),
So when error occurs during looping, it is correct to only mark "need
return failure" and continue looping.
Since simplify_symbols() is a static function (not an API to outside),
it is better to change the function return type to 'bool', so that can
skip processing error number details incorrectly.
Signed-off-by: root <root@dhcp122.asianux.net>
---
kernel/module.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index b049939..445a960 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1956,14 +1956,18 @@ static int verify_export_symbols(struct module *mod)
return 0;
}
-/* Change all symbols so that st_value encodes the pointer directly. */
-static int simplify_symbols(struct module *mod, const struct load_info *info)
+/*
+ * Change all symbols so that st_value encodes the pointer directly.
+ *
+ * Return true if succeed, or false if at least 1 failure occurs.
+ */
+static bool simplify_symbols(struct module *mod, const struct load_info *info)
{
Elf_Shdr *symsec = &info->sechdrs[info->index.sym];
Elf_Sym *sym = (void *)symsec->sh_addr;
unsigned long secbase;
unsigned int i;
- int ret = 0;
+ bool ret = true;
const struct kernel_symbol *ksym;
for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
@@ -1976,7 +1980,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
pr_debug("Common symbol: %s\n", name);
printk("%s: please compile with -fno-common\n",
mod->name);
- ret = -ENOEXEC;
+ /* Mark return result and continue looping */
+ ret = false;
break;
case SHN_ABS:
@@ -1999,7 +2004,8 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n",
mod->name, name, PTR_ERR(ksym));
- ret = PTR_ERR(ksym) ?: -ENOENT;
+ /* Mark return result and continue looping */
+ ret = false;
break;
default:
@@ -3267,8 +3273,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
setup_modinfo(mod, info);
/* Fix up syms, so that st_value is a pointer to location. */
- err = simplify_symbols(mod, info);
- if (err < 0)
+ if (!simplify_symbols(mod, info))
goto free_modinfo;
err = apply_relocations(mod, info);
--
1.7.11.7
next prev parent reply other threads:[~2013-05-13 12:25 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-07 6:27 [PATCH] kernel/module.c: for looping, need use 'goto' instead of 'break' to jump out in time Chen Gang
2013-05-08 0:29 ` Rusty Russell
2013-05-08 3:09 ` Chen Gang
2013-05-13 1:17 ` Rusty Russell
2013-05-13 3:33 ` Chen Gang
2013-05-13 12:24 ` Chen Gang [this message]
2013-05-14 2:16 ` [PATCH v2] kernel/module.c: cleanup patch for looping, let return 'bool' value instead of real error number Chen Gang
2013-05-17 4:33 ` [PATCH v3] kernel/module.c: need return the first error code to upper caller when error occurs Chen Gang
2013-05-22 11:26 ` Chen Gang
2013-05-23 3:54 ` Rusty Russell
2013-05-23 5:13 ` Chen Gang
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=5190DB74.6050100@asianux.com \
--to=gang.chen@asianux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=torvalds@linux-foundation.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