[cocci] [RFC PATCH 2/6] debugfs: Add helper functions for debugfs_node encapsulation

David Reaver
2025-02-10T05:22:02Z

Once debugfs_node becomes a struct, users will need helper functions since
direct access to the underlying dentry will no longer be possible. This
commit introduces these helpers, which will be used in the automated
Coccinelle conversion.

Signed-off-by: David Reaver <me@davidreaver.com>
---
fs/debugfs/inode.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/debugfs.h | 41 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 79 insertions(+)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 75715d8877ee..6892538d9d49 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -353,6 +353,44 @@ struct dentry *debugfs_lookup(const char *name, struct dentry *parent)
}
EXPORT_SYMBOL_GPL(debugfs_lookup);

+char *debugfs_node_path_raw(struct debugfs_node *node, char *buf, size_t buflen)
+{
+ return dentry_path_raw(node, buf, buflen);
+}
+EXPORT_SYMBOL_GPL(debugfs_node_path_raw);
+
+struct debugfs_node *debugfs_node_get(struct debugfs_node *node)
+{
+ return dget(node);
+}
+EXPORT_SYMBOL_GPL(debugfs_node_get);
+
+void debugfs_node_put(struct debugfs_node *node)
+{
+ dput(node);
+}
+EXPORT_SYMBOL_GPL(debugfs_node_put);
+
+struct inode *debugfs_node_inode(struct debugfs_node *node)
+{
+ return d_inode(node);
+}
+EXPORT_SYMBOL_GPL(debugfs_node_inode);
+
+struct debugfs_node *debugfs_node_from_dentry(struct dentry *dentry)
+{
+ if (dentry->d_sb->s_op == &debugfs_super_operations)
+ return dentry;
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(debugfs_node_from_dentry);
+
+struct dentry *debugfs_node_dentry(struct debugfs_node *node)
+{
+ return node;
+}
+EXPORT_SYMBOL_GPL(debugfs_node_dentry);
+
static struct dentry *start_creating(const char *name, struct dentry *parent)
{
struct dentry *dentry;
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index e6ee571e8c36..738a990f99cd 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -79,6 +79,18 @@ struct debugfs_short_fops {

struct dentry *debugfs_lookup(const char *name, struct dentry *parent);

+char *debugfs_node_path_raw(struct debugfs_node *node, char *buf, size_t buflen);
+
+struct debugfs_node *debugfs_node_get(struct debugfs_node *node);
+
+void debugfs_node_put(struct debugfs_node *node);
+
+struct inode *debugfs_node_inode(struct debugfs_node *node);
+
+struct debugfs_node *debugfs_node_from_dentry(struct dentry *dentry);
+
+struct dentry *debugfs_node_dentry(struct debugfs_node *node);
+
struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
struct dentry *parent, void *data,
const void *aux,
@@ -271,6 +283,35 @@ static inline struct dentry *debugfs_lookup(const char *name,
return ERR_PTR(-ENODEV);
}

+static inline char *debugfs_node_path_raw(struct debugfs_node *node, char *buf,
+ size_t buflen)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+static inline struct debugfs_node *debugfs_node_get(struct debugfs_node *node)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+void debugfs_node_put(struct debugfs_node *node)
+{ }
+
+struct inode *debugfs_node_inode(struct debugfs_node *node)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+struct debugfs_node *debugfs_node_from_dentry(struct dentry *dentry)
+{
+ return ERR_PTR(-ENODEV);
+}
+
+struct dentry *debugfs_node_dentry(struct debugfs_node *node)
+{
+ return ERR_PTR(-ENODEV);
+}
+
static inline struct dentry *debugfs_create_file_aux(const char *name,
umode_t mode, struct dentry *parent,
void *data, void *aux,