diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2008-03-10 14:43:53 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-03-10 21:01:20 -0400 |
commit | e24e2e64c468c8060bb7173abecdf11d00ed5751 (patch) | |
tree | b03faa2fd187a207d0a2e78af75a787a66ab21fe | |
parent | 6c5db22d280302c33dafb309c25bf2841fb99c37 (diff) |
modules: warn about suspicious return values from module's ->init() hook
Return value convention of module's init functions is 0/-E. Sometimes,
e.g. during forward-porting mistakes happen and buggy module created,
where result of comparison "workqueue != NULL" is propagated all the way up
to sys_init_module. What happens is that some other module created
workqueue in question, our module created it again and module was
successfully loaded.
Or it could be some other bug.
Let's make such mistakes much more visible. In retrospective, such
messages would noticeably shorten some of my head-scratching sessions.
Note, that dump_stack() is just a way to get attention from user. Sample
message:
sys_init_module: 'foo'->init suspiciously returned 1, it should follow 0/-E convention
sys_init_module: loading module anyway...
Pid: 4223, comm: modprobe Not tainted 2.6.24-25f666300625d894ebe04bac2b4b3aadb907c861 #5
Call Trace:
[<ffffffff80254b05>] sys_init_module+0xe5/0x1d0
[<ffffffff8020b39b>] system_call_after_swapgs+0x7b/0x80
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | kernel/module.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/kernel/module.c b/kernel/module.c index 68d05d2f4d8a..5d437bffd8dc 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -2178,6 +2178,14 @@ sys_init_module(void __user *umod, | |||
2178 | wake_up(&module_wq); | 2178 | wake_up(&module_wq); |
2179 | return ret; | 2179 | return ret; |
2180 | } | 2180 | } |
2181 | if (ret > 0) { | ||
2182 | printk(KERN_WARNING "%s: '%s'->init suspiciously returned %d, " | ||
2183 | "it should follow 0/-E convention\n" | ||
2184 | KERN_WARNING "%s: loading module anyway...\n", | ||
2185 | __func__, mod->name, ret, | ||
2186 | __func__); | ||
2187 | dump_stack(); | ||
2188 | } | ||
2181 | 2189 | ||
2182 | /* Now it's a first class citizen! Wake up anyone waiting for it. */ | 2190 | /* Now it's a first class citizen! Wake up anyone waiting for it. */ |
2183 | mod->state = MODULE_STATE_LIVE; | 2191 | mod->state = MODULE_STATE_LIVE; |