diff mbox series

[3/4] media: mc: add media_debugfs_root()

Message ID 3d18c4c2dae3a2b4c4156ad791b4dec50dcda96c.1724848660.git.hverkuil-cisco@xs4all.nl (mailing list archive)
State New
Headers show
Series media: mc: add manual request completion support | expand

Commit Message

Hans Verkuil Aug. 28, 2024, 12:37 p.m. UTC
This new function returns the dentry of the top-level debugfs "media"
directory. If it does not exist yet, then it is created first.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
---
 drivers/media/mc/mc-devnode.c | 15 +++++++++++++++
 include/media/media-devnode.h | 14 ++++++++++++++
 2 files changed, 29 insertions(+)
diff mbox series

Patch

diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c
index 318e267e798e..906c10fe26f0 100644
--- a/drivers/media/mc/mc-devnode.c
+++ b/drivers/media/mc/mc-devnode.c
@@ -20,6 +20,7 @@ 
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/debugfs.h>
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/module.h>
@@ -45,6 +46,18 @@  static dev_t media_dev_t;
 static DEFINE_MUTEX(media_devnode_lock);
 static DECLARE_BITMAP(media_devnode_nums, MEDIA_NUM_DEVICES);
 
+static struct dentry *media_debugfs_root_dir;
+
+#ifdef CONFIG_DEBUG_FS
+struct dentry *media_debugfs_root(void)
+{
+	if (!media_debugfs_root_dir)
+		media_debugfs_root_dir = debugfs_create_dir("media", NULL);
+	return media_debugfs_root_dir;
+}
+EXPORT_SYMBOL_GPL(media_debugfs_root);
+#endif
+
 /* Called when the last user of the media device exits. */
 static void media_devnode_release(struct device *cd)
 {
@@ -316,6 +329,8 @@  static void __exit media_devnode_exit(void)
 {
 	bus_unregister(&media_bus_type);
 	unregister_chrdev_region(media_dev_t, MEDIA_NUM_DEVICES);
+	debugfs_remove_recursive(media_debugfs_root_dir);
+	media_debugfs_root_dir = NULL;
 }
 
 subsys_initcall(media_devnode_init);
diff --git a/include/media/media-devnode.h b/include/media/media-devnode.h
index d27c1c646c28..e9f272ebd3d0 100644
--- a/include/media/media-devnode.h
+++ b/include/media/media-devnode.h
@@ -165,4 +165,18 @@  static inline int media_devnode_is_registered(struct media_devnode *devnode)
 	return test_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
 }
 
+/**
+ * media_debugfs_root - returns the dentry of the top-level "media" debugfs dir
+ *
+ * If this directory does not yet exist, then it will be created.
+ */
+#ifdef CONFIG_DEBUG_FS
+struct dentry *media_debugfs_root(void);
+#else
+static inline struct dentry *media_debugfs_root(void)
+{
+	return NULL;
+}
+#endif
+
 #endif /* _MEDIA_DEVNODE_H */