diff options
-rw-r--r-- | fs/debugfs/file.c | 54 | ||||
-rw-r--r-- | include/linux/debugfs.h | 16 |
2 files changed, 69 insertions, 1 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 76c08c2beb2f..a2f8ec70fe8d 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/io.h> | 22 | #include <linux/io.h> |
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/atomic.h> | 24 | #include <linux/atomic.h> |
25 | #include <linux/device.h> | ||
25 | 26 | ||
26 | static ssize_t default_read_file(struct file *file, char __user *buf, | 27 | static ssize_t default_read_file(struct file *file, char __user *buf, |
27 | size_t count, loff_t *ppos) | 28 | size_t count, loff_t *ppos) |
@@ -761,3 +762,56 @@ struct dentry *debugfs_create_regset32(const char *name, umode_t mode, | |||
761 | EXPORT_SYMBOL_GPL(debugfs_create_regset32); | 762 | EXPORT_SYMBOL_GPL(debugfs_create_regset32); |
762 | 763 | ||
763 | #endif /* CONFIG_HAS_IOMEM */ | 764 | #endif /* CONFIG_HAS_IOMEM */ |
765 | |||
766 | struct debugfs_devm_entry { | ||
767 | int (*read)(struct seq_file *seq, void *data); | ||
768 | struct device *dev; | ||
769 | }; | ||
770 | |||
771 | static int debugfs_devm_entry_open(struct inode *inode, struct file *f) | ||
772 | { | ||
773 | struct debugfs_devm_entry *entry = inode->i_private; | ||
774 | |||
775 | return single_open(f, entry->read, entry->dev); | ||
776 | } | ||
777 | |||
778 | static const struct file_operations debugfs_devm_entry_ops = { | ||
779 | .owner = THIS_MODULE, | ||
780 | .open = debugfs_devm_entry_open, | ||
781 | .release = single_release, | ||
782 | .read = seq_read, | ||
783 | .llseek = seq_lseek | ||
784 | }; | ||
785 | |||
786 | /** | ||
787 | * debugfs_create_devm_seqfile - create a debugfs file that is bound to device. | ||
788 | * | ||
789 | * @dev: device related to this debugfs file. | ||
790 | * @name: name of the debugfs file. | ||
791 | * @parent: a pointer to the parent dentry for this file. This should be a | ||
792 | * directory dentry if set. If this parameter is %NULL, then the | ||
793 | * file will be created in the root of the debugfs filesystem. | ||
794 | * @read_fn: function pointer called to print the seq_file content. | ||
795 | */ | ||
796 | struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name, | ||
797 | struct dentry *parent, | ||
798 | int (*read_fn)(struct seq_file *s, | ||
799 | void *data)) | ||
800 | { | ||
801 | struct debugfs_devm_entry *entry; | ||
802 | |||
803 | if (IS_ERR(parent)) | ||
804 | return ERR_PTR(-ENOENT); | ||
805 | |||
806 | entry = devm_kzalloc(dev, sizeof(*entry), GFP_KERNEL); | ||
807 | if (!entry) | ||
808 | return ERR_PTR(-ENOMEM); | ||
809 | |||
810 | entry->read = read_fn; | ||
811 | entry->dev = dev; | ||
812 | |||
813 | return debugfs_create_file(name, S_IRUGO, parent, entry, | ||
814 | &debugfs_devm_entry_ops); | ||
815 | } | ||
816 | EXPORT_SYMBOL_GPL(debugfs_create_devm_seqfile); | ||
817 | |||
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 4d0b4d1aa132..4bbe2ace972a 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h | |||
@@ -99,13 +99,18 @@ struct dentry *debugfs_create_u32_array(const char *name, umode_t mode, | |||
99 | struct dentry *parent, | 99 | struct dentry *parent, |
100 | u32 *array, u32 elements); | 100 | u32 *array, u32 elements); |
101 | 101 | ||
102 | struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name, | ||
103 | struct dentry *parent, | ||
104 | int (*read_fn)(struct seq_file *s, | ||
105 | void *data)); | ||
106 | |||
102 | bool debugfs_initialized(void); | 107 | bool debugfs_initialized(void); |
103 | 108 | ||
104 | #else | 109 | #else |
105 | 110 | ||
106 | #include <linux/err.h> | 111 | #include <linux/err.h> |
107 | 112 | ||
108 | /* | 113 | /* |
109 | * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled | 114 | * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled |
110 | * so users have a chance to detect if there was a real error or not. We don't | 115 | * so users have a chance to detect if there was a real error or not. We don't |
111 | * want to duplicate the design decision mistakes of procfs and devfs again. | 116 | * want to duplicate the design decision mistakes of procfs and devfs again. |
@@ -251,6 +256,15 @@ static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t | |||
251 | return ERR_PTR(-ENODEV); | 256 | return ERR_PTR(-ENODEV); |
252 | } | 257 | } |
253 | 258 | ||
259 | static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev, | ||
260 | const char *name, | ||
261 | struct dentry *parent, | ||
262 | int (*read_fn)(struct seq_file *s, | ||
263 | void *data)) | ||
264 | { | ||
265 | return ERR_PTR(-ENODEV); | ||
266 | } | ||
267 | |||
254 | #endif | 268 | #endif |
255 | 269 | ||
256 | #endif | 270 | #endif |