linux-modules.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Gomez <da.gomez@kernel.org>
To: Luis Chamberlain <mcgrof@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	 Daniel Gomez <da.gomez@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	 Aaron Tomlin <atomlin@atomlin.com>,
	Jonathan Corbet <corbet@lwn.net>,
	 Lucas De Marchi <demarchi@kernel.org>
Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-doc@vger.kernel.org, Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH 1/2] module: add -EEXIST documentation
Date: Thu, 18 Dec 2025 21:59:44 +0100	[thread overview]
Message-ID: <20251218-dev-module-init-eexists-modules-docs-v1-1-361569aa782a@samsung.com> (raw)
In-Reply-To: <20251218-dev-module-init-eexists-modules-docs-v1-0-361569aa782a@samsung.com>

From: Daniel Gomez <da.gomez@samsung.com>

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.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 kernel/module/main.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index a8394d81174f..655a780981d3 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -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);

-- 
2.52.0


  reply	other threads:[~2025-12-18 21:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-18 20:59 [PATCH 0/2] module: add -EEXIST module_init() reservation docs Daniel Gomez
2025-12-18 20:59 ` Daniel Gomez [this message]
2025-12-18 20:59 ` [PATCH 2/2] docs: hacking: clarify reserved -EEXIST in module_init() Daniel Gomez

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=20251218-dev-module-init-eexists-modules-docs-v1-1-361569aa782a@samsung.com \
    --to=da.gomez@kernel.org \
    --cc=atomlin@atomlin.com \
    --cc=corbet@lwn.net \
    --cc=da.gomez@samsung.com \
    --cc=demarchi@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=samitolvanen@google.com \
    /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;
as well as URLs for NNTP newsgroup(s).