Linux driver-core infrastructure
 help / color / mirror / Atom feed
From: Paul Martin <paul.martin@codethink.co.uk>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	driver-core@lists.linux.dev
Cc: rafael@kernel.org, dakr@kernel.org,
	Paul Martin <paul.martin@codethink.co.uk>
Subject: [PATCH] Fix debugfs error returns to match documentation and vice versa
Date: Wed,  6 May 2026 17:58:19 +0100	[thread overview]
Message-ID: <20260506165819.58974-1-paul.martin@codethink.co.uk> (raw)

Many of debugfs's exported functions call `debugfs_start_creating()`
and return the errors it returns.  These differ from the documentation
in that:

- `ERR_PTR(-EPERM)` is returned if debugfs is present in the kernel
  but has been disabled by configuration or boot option.

- `ERR_PTR(-ENOENT)` is returned if debugfs is not registered in the
  kernel.

At no point does it return `ERR_PTR(-ENODEV)`.

This patch fixes the returned error in the second scenario to match
the documentation and also the documentation to mention the returned
error for the first scenario.

The comment block above `debugfs_lookup()` says it returns
`ERR_PTR(-ENODEV)` if debugfs is not enabled, but instead it returns
NULL.  This patch fixes the code to match the documentation.
---
 Documentation/filesystems/debugfs.rst |  4 +++-
 fs/debugfs/inode.c                    | 13 +++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Documentation/filesystems/debugfs.rst b/Documentation/filesystems/debugfs.rst
index 55f807293924..b092b0015b98 100644
--- a/Documentation/filesystems/debugfs.rst
+++ b/Documentation/filesystems/debugfs.rst
@@ -41,7 +41,9 @@ dentry pointer which can be used to create files in the directory (and to
 clean it up at the end).  An ERR_PTR(-ERROR) return value indicates that
 something went wrong.  If ERR_PTR(-ENODEV) is returned, that is an
 indication that the kernel has been built without debugfs support and none
-of the functions described below will work.
+of the functions described below will work.  If ERR_PTR(-EPERM) is returned
+debugfs support was compiled in but has been disabled by default in the
+kernel configuration or by passing ``debugfs=off`` on the kernel commandline.
 
 The most general way to create a file within a debugfs directory is with::
 
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 4598142355b9..fc521bf9f191 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -346,7 +346,10 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
 {
 	struct dentry *dentry;
 
-	if (!debugfs_initialized() || IS_ERR_OR_NULL(name) || IS_ERR(parent))
+	if (!debugfs_initialized() || !debugfs_enabled)
+		return ERR_PTR(-ENODEV);
+
+	if (IS_ERR_OR_NULL(name) || IS_ERR(parent))
 		return NULL;
 
 	if (!parent)
@@ -369,7 +372,7 @@ static struct dentry *debugfs_start_creating(const char *name,
 		return ERR_PTR(-EPERM);
 
 	if (!debugfs_initialized())
-		return ERR_PTR(-ENOENT);
+		return ERR_PTR(-ENODEV);
 
 	pr_debug("creating file '%s'\n", name);
 
@@ -562,6 +565,9 @@ EXPORT_SYMBOL_GPL(debugfs_create_file_size);
  * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  * returned.
  *
+ * If debugfs is enabled in the kernel but disabled by configuration,
+ * the value -%EPERM will be returned.
+ *
  * NOTE: it's expected that most callers should _ignore_ the errors returned
  * by this function. Other debugfs functions handle the fact that the "dentry"
  * passed to them could be an error and they don't crash in that case.
@@ -659,6 +665,9 @@ EXPORT_SYMBOL(debugfs_create_automount);
  *
  * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  * returned.
+ *
+ * If debugfs is enabled in the kernel but disabled by configuration,
+ * the value -%EPERM will be returned.
  */
 struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 				      const char *target)
-- 
2.53.0


                 reply	other threads:[~2026-05-06 16:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260506165819.58974-1-paul.martin@codethink.co.uk \
    --to=paul.martin@codethink.co.uk \
    --cc=dakr@kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=rafael@kernel.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