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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 drivers/media/mc/mc-devnode.c | 15 +++++++++++++++
 include/media/media-devnode.h | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

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 */
-- 
2.43.0





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux