debugfs: Export bool read/write functions

The file read/write functions for bools have no special dependencies
on debugfs internals and are sufficiently non-trivial to be worth
exporting so clients can re-use the implementation.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Richard Fitzgerald 2015-06-23 14:32:54 +01:00 committed by Mark Brown
parent bc0195aad0
commit 0642ef6f29
2 changed files with 28 additions and 6 deletions

View File

@ -435,8 +435,8 @@ struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
} }
EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
static ssize_t read_file_bool(struct file *file, char __user *user_buf, ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char buf[3]; char buf[3];
u32 *val = file->private_data; u32 *val = file->private_data;
@ -449,9 +449,10 @@ static ssize_t read_file_bool(struct file *file, char __user *user_buf,
buf[2] = 0x00; buf[2] = 0x00;
return simple_read_from_buffer(user_buf, count, ppos, buf, 2); return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
} }
EXPORT_SYMBOL_GPL(debugfs_read_file_bool);
static ssize_t write_file_bool(struct file *file, const char __user *user_buf, ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
char buf[32]; char buf[32];
size_t buf_size; size_t buf_size;
@ -468,10 +469,11 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
return count; return count;
} }
EXPORT_SYMBOL_GPL(debugfs_write_file_bool);
static const struct file_operations fops_bool = { static const struct file_operations fops_bool = {
.read = read_file_bool, .read = debugfs_read_file_bool,
.write = write_file_bool, .write = debugfs_write_file_bool,
.open = simple_open, .open = simple_open,
.llseek = default_llseek, .llseek = default_llseek,
}; };

View File

@ -116,6 +116,12 @@ struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
bool debugfs_initialized(void); bool debugfs_initialized(void);
ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos);
ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos);
#else #else
#include <linux/err.h> #include <linux/err.h>
@ -282,6 +288,20 @@ static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
} }
static inline ssize_t debugfs_read_file_bool(struct file *file,
char __user *user_buf,
size_t count, loff_t *ppos)
{
return -ENODEV;
}
static inline ssize_t debugfs_write_file_bool(struct file *file,
const char __user *user_buf,
size_t count, loff_t *ppos)
{
return -ENODEV;
}
#endif #endif
#endif #endif