lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241206111629.3521865-2-shaojijie@huawei.com>
Date: Fri, 6 Dec 2024 19:16:22 +0800
From: Jijie Shao <shaojijie@...wei.com>
To: <davem@...emloft.net>, <edumazet@...gle.com>, <kuba@...nel.org>,
	<pabeni@...hat.com>, <andrew+netdev@...n.ch>, <horms@...nel.org>,
	<gregkh@...uxfoundation.org>
CC: <shenjian15@...wei.com>, <wangpeiyang1@...wei.com>,
	<liuyonglong@...wei.com>, <chenhao418@...wei.com>, <sudongming1@...wei.com>,
	<xujunsheng@...wei.com>, <shiyongbang@...wei.com>, <libaihan@...wei.com>,
	<jonathan.cameron@...wei.com>, <shameerali.kolothum.thodi@...wei.com>,
	<salil.mehta@...wei.com>, <netdev@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>, <shaojijie@...wei.com>, <hkelam@...vell.com>
Subject: [PATCH V5 net-next 1/8] debugfs: Add debugfs_create_devm_dir() helper

Add debugfs_create_devm_dir() helper

Signed-off-by: Jijie Shao <shaojijie@...wei.com>
---
 fs/debugfs/inode.c      | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/debugfs.h | 10 ++++++++++
 2 files changed, 46 insertions(+)

diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 38a9c7eb97e6..f682c4952a27 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -610,6 +610,42 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
 }
 EXPORT_SYMBOL_GPL(debugfs_create_dir);
 
+static void debugfs_remove_devm(void *dentry_rwa)
+{
+	struct dentry *dentry = dentry_rwa;
+
+	debugfs_remove(dentry);
+}
+
+/**
+ * debugfs_create_devm_dir - Managed debugfs_create_dir()
+ * @dev: Device that owns the action
+ * @name: a pointer to a string containing the name of the directory to
+ *        create.
+ * @parent: a pointer to the parent dentry for this file.  This should be a
+ *          directory dentry if set.  If this parameter is NULL, then the
+ *          directory will be created in the root of the debugfs filesystem.
+ * Managed debugfs_create_dir(). dentry will automatically be remove on
+ * driver detach.
+ */
+struct dentry *debugfs_create_devm_dir(struct device *dev, const char *name,
+				       struct dentry *parent)
+{
+	struct dentry *dentry;
+	int ret;
+
+	dentry = debugfs_create_dir(name, parent);
+	if (IS_ERR(dentry))
+		return dentry;
+
+	ret = devm_add_action_or_reset(dev, debugfs_remove_devm, dentry);
+	if (ret)
+		ERR_PTR(ret);
+
+	return dentry;
+}
+EXPORT_SYMBOL_GPL(debugfs_create_devm_dir);
+
 /**
  * debugfs_create_automount - create automount point in the debugfs filesystem
  * @name: a pointer to a string containing the name of the file to create.
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h
index 59444b495d49..19d8c322debe 100644
--- a/include/linux/debugfs.h
+++ b/include/linux/debugfs.h
@@ -139,6 +139,9 @@ void debugfs_create_file_size(const char *name, umode_t mode,
 
 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
 
+struct dentry *debugfs_create_devm_dir(struct device *dev, const char *name,
+				       struct dentry *parent);
+
 struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
 				      const char *dest);
 
@@ -286,6 +289,13 @@ static inline struct dentry *debugfs_create_dir(const char *name,
 	return ERR_PTR(-ENODEV);
 }
 
+static inline struct dentry *debugfs_create_devm_dir(struct device *dev,
+						     const char *name,
+						     struct dentry *parent)
+{
+	return ERR_PTR(-ENODEV);
+}
+
 static inline struct dentry *debugfs_create_symlink(const char *name,
 						    struct dentry *parent,
 						    const char *dest)
-- 
2.33.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ