module: add -EEXIST module_init() reservation docs
Subsystems (2)
Daniel Gomez
maintainercover module: add -EEXIST module_init() reservation docs
This series documents the -EEXIST error code reservation in the module loader, building on Lucas's patches [1] that add the runtime safety net.
When module_init() returns -EEXIST, kmod interprets this as "module already loaded" and reports success, hiding real init failures. Lucas's patches warn and override this to -EBUSY. These patches document this convention to prevent future cases.
This was originally reported in this thread [2].
---
Daniel Gomez (2):
module: add -EEXIST documentation
docs: hacking: clarify reserved -EEXIST in module_init()
Documentation/kernel-hacking/hacking.rst | 7 +++++++ kernel/module/main.c | 8 ++++++++ 2 files changed, 15 insertions(+)
---
base-commit: e5f0a698b34ed76002dc5cff3804a61c80233a7a
change-id: 20251218-dev-module-init-eexists-modules-docs-1dc7cb7a96bb
prerequisite-change-id: 20251013-module-warn-ret-59f085298055:v1
prerequisite-patch-id: c3e4f5b5d01c2b48b4c94e51a60469cb74691853
prerequisite-patch-id: 2d5a726a75f3b9d9c256b8478fb6115a92f04354
Best regards,
Signature · 1 line
Daniel Gomez <[email protected]>
Daniel Gomez
maintainerPATCH 1/2 module: add -EEXIST documentation
From: Daniel Gomez <[email protected]>
The error code -EEXIST is reserved by the kernel module loader to indicate that a module with the same name is already loaded. Add a comment to clarify what this means for module authors and maintainers to ensure the module_init() path return error do not conflict with the reserved one.
--- kernel/module/main.c | 8 ++++++++ 1 file changed, 8 insertions(+)
kernel/module/main.c +8 -0
@@ -3038,6 +3038,14 @@ static noinline int do_init_module(struct module *mod)if (mod->init !=NULL ) ret =do_one_initcall (mod->init);if (ret <0 ) { +/* +* -EEXIST is reserved by the module loader to mean "already loaded". kmod +* interprets this as success, hiding real module failures. Override with +* -EBUSY and warn. +* +* Module authors: use -EBUSY or -EALREADY instead of -EEXIST. +* See Documentation/kernel-hacking/hacking.rst +*/ if (ret == -EEXIST ) {pr_warn ("%s: init suspiciously returned -EEXIST: Overriding with -EBUSY\n" , mod->name);
Signature · 1 line
2.52.0
Daniel Gomez
maintainerPATCH 2/2 docs: hacking: clarify reserved -EEXIST in module_init()
In reply to Daniel GomezFrom: Daniel Gomez <[email protected]>
The error code -EEXIST is reserved by the kernel module loader to indicate that a module with the same name is already loaded. Add a warning note to clarify what these means for module authors and maintainers to ensure the module_init() path return error do not conflict with the reserved one.
--- Documentation/kernel-hacking/hacking.rst | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/kernel-hacking/hacking.rst +7 -0
@@ -459,6 +459,13 @@ to fail (unfortunately, this has no effect if the module is compiled into the kernel). This function is called in user context with interrupts enabled, so it can sleep. +.. warning:: + + The error code ``-EEXIST`` is reserved by the module loader to + indicate a module is already loaded. kmod interprets this as success, + so ``module_init()`` must never return ``-EEXIST``. Use ``-EBUSY`` or + ``-EALREADY`` instead. + :c:func:`module_exit()` -----------------------
Signature · 1 line
2.52.0