sysfs: collapse fs/sysfs/bin.c::fill_read() into read()
read() is simple enough and fill_read() being in a separate function doesn't add anything. Let's collapse it into read(). This will make merging bin file handling with regular file. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Родитель
91270162bf
Коммит
3ff65d3cb0
|
@ -44,30 +44,12 @@ struct bin_buffer {
|
||||||
struct hlist_node list;
|
struct hlist_node list;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static ssize_t
|
||||||
fill_read(struct file *file, char *buffer, loff_t off, size_t count)
|
read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
|
||||||
{
|
{
|
||||||
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
|
struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
|
||||||
struct bin_attribute *attr = attr_sd->s_bin_attr.bin_attr;
|
struct bin_attribute *attr = attr_sd->s_bin_attr.bin_attr;
|
||||||
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
|
struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
|
||||||
int rc;
|
|
||||||
|
|
||||||
/* need attr_sd for attr, its parent for kobj */
|
|
||||||
if (!sysfs_get_active(attr_sd))
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
rc = -EIO;
|
|
||||||
if (attr->read)
|
|
||||||
rc = attr->read(file, kobj, attr, buffer, off, count);
|
|
||||||
|
|
||||||
sysfs_put_active(attr_sd);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t
|
|
||||||
read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
|
|
||||||
{
|
|
||||||
struct bin_buffer *bb = file->private_data;
|
struct bin_buffer *bb = file->private_data;
|
||||||
int size = file_inode(file)->i_size;
|
int size = file_inode(file)->i_size;
|
||||||
loff_t offs = *off;
|
loff_t offs = *off;
|
||||||
|
@ -88,8 +70,20 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
/* need attr_sd for attr, its parent for kobj */
|
||||||
mutex_lock(&bb->mutex);
|
mutex_lock(&bb->mutex);
|
||||||
count = fill_read(file, buf, offs, count);
|
if (!sysfs_get_active(attr_sd)) {
|
||||||
|
count = -ENODEV;
|
||||||
|
mutex_unlock(&bb->mutex);
|
||||||
|
goto out_free;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attr->read)
|
||||||
|
count = attr->read(file, kobj, attr, buf, offs, count);
|
||||||
|
else
|
||||||
|
count = -EIO;
|
||||||
|
|
||||||
|
sysfs_put_active(attr_sd);
|
||||||
mutex_unlock(&bb->mutex);
|
mutex_unlock(&bb->mutex);
|
||||||
|
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче