insmod 不会抛出正数 return 的错误

insmod not throwing error for a positive return

我正在编写我的第一个内核模块,它是一个简单的 Hello World 内核模块。我遵循的 tldp 指南说,如果 init_module 函数 return 是非零值,则 insmod 不会加载模块。 它在 return 一些负数时按预期工作,但在试验时我注意到 insmod 正在加载我的模块,即使 return 值为正数。

请解释原因?

比如我return-185,insmod直接说无法加载模块

但是当我 return 185 时,它正在通知一个可疑的 return 但仍在加载模块。 这是 "return 185".

的日志
[19398.947857] do_init_module: 'hello_1'->init suspiciously returned 185, it should follow 0/-E convention
do_init_module: loading module anyway...
[19398.947859] CPU: 0 PID: 11812 Comm: insmod Tainted: P           OE  3.19.0-15-generic #15-Ubuntu
[19398.947860] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
[19398.947861]  ffffffffc06c3000 ffff880059347d98 ffffffff817c2205 0000000000000007
[19398.947862]  ffffffffc06c3018 ffff880059347ee8 ffffffff810f9a2d ffffffff810f51d0
[19398.947864]  ffff8800db64ad10 ffff880059347e40 ffffffffc06c3018 ffffffffc0391000
[19398.947865] Call Trace:
[19398.947869]  [<ffffffff817c2205>] dump_stack+0x45/0x57
[19398.947872]  [<ffffffff810f9a2d>] load_module+0x160d/0x1ce0
[19398.947873]  [<ffffffff810f51d0>] ? store_uevent+0x40/0x40
[19398.947875]  [<ffffffff810fa276>] SyS_finit_module+0x86/0xb0
[19398.947877]  [<ffffffff817c934d>] system_call_fastpath+0x16/0x1b

这会在 "return -185"

的控制台上打印出来
insmod: ERROR: could not insert module hello-1.ko: Unknown error 185

init_module 函数 应该 return 0 或负错误代码。您可以将 returning 正值视为导致 undefined behaviour.

当前内核将正值解释为 success,但将警告打印到系统日志中。可以使用 dmesg.

读取此日志