summaryrefslogtreecommitdiffstats
path: root/fs/proc/generic.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-05-15 15:57:23 +0200
committerChristoph Hellwig <hch@lst.de>2018-05-16 07:23:35 +0200
commit3f3942aca6da351a12543aa776467791b63b3a78 (patch)
tree31030e086ea36920e07078ea2289b9b72c0b2939 /fs/proc/generic.c
parent44414d82cfe0f68cb59d0a42f599ccd893ae0032 (diff)
downloadlinux-3f3942aca6da351a12543aa776467791b63b3a78.tar.bz2
proc: introduce proc_create_single{,_data}
Variants of proc_create{,_data} that directly take a seq_file show callback and drastically reduces the boilerplate code in the callers. All trivial callers converted over. Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/proc/generic.c')
-rw-r--r--fs/proc/generic.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index f87cb0053387..02bb1914f5f7 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -588,6 +588,35 @@ struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
}
EXPORT_SYMBOL(proc_create_seq_private);
+static int proc_single_open(struct inode *inode, struct file *file)
+{
+ struct proc_dir_entry *de = PDE(inode);
+
+ return single_open(file, de->single_show, de->data);
+}
+
+static const struct file_operations proc_single_fops = {
+ .open = proc_single_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
+ struct proc_dir_entry *parent,
+ int (*show)(struct seq_file *, void *), void *data)
+{
+ struct proc_dir_entry *p;
+
+ p = proc_create_reg(name, mode, &parent, data);
+ if (!p)
+ return NULL;
+ p->proc_fops = &proc_single_fops;
+ p->single_show = show;
+ return proc_register(parent, p);
+}
+EXPORT_SYMBOL(proc_create_single_data);
+
void proc_set_size(struct proc_dir_entry *de, loff_t size)
{
de->size = size;