提交 93e3cd82 编写于 作者: T Tejun Heo 提交者: Greg Kroah-Hartman

sysfs: fix error handling in binattr write()

Error handling in fs/sysfs/bin.c:write() was wrong because size_t
count is used to receive return value from flush_write() which is
negative on failure.

This patch updates write() such that int variable is used instead.
read() is updated the same way for consistency.
Signed-off-by: NTejun Heo <htejun@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 7a23ad44
...@@ -33,16 +33,13 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count) ...@@ -33,16 +33,13 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
} }
static ssize_t static ssize_t
read(struct file * file, char __user * userbuf, size_t count, loff_t * off) read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
{ {
char *buffer = file->private_data; char *buffer = file->private_data;
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
int size = dentry->d_inode->i_size; int size = dentry->d_inode->i_size;
loff_t offs = *off; loff_t offs = *off;
int ret; int count = min_t(size_t, bytes, PAGE_SIZE);
if (count > PAGE_SIZE)
count = PAGE_SIZE;
if (size) { if (size) {
if (offs > size) if (offs > size)
...@@ -51,15 +48,14 @@ read(struct file * file, char __user * userbuf, size_t count, loff_t * off) ...@@ -51,15 +48,14 @@ read(struct file * file, char __user * userbuf, size_t count, loff_t * off)
count = size - offs; count = size - offs;
} }
ret = fill_read(dentry, buffer, offs, count); count = fill_read(dentry, buffer, offs, count);
if (ret < 0) if (count < 0)
return ret; return count;
count = ret;
if (copy_to_user(userbuf, buffer, count)) if (copy_to_user(userbuf, buffer, count))
return -EFAULT; return -EFAULT;
pr_debug("offs = %lld, *off = %lld, count = %zd\n", offs, *off, count); pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count);
*off = offs + count; *off = offs + count;
...@@ -78,16 +74,15 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count) ...@@ -78,16 +74,15 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count)
return attr->write(kobj, buffer, offset, count); return attr->write(kobj, buffer, offset, count);
} }
static ssize_t write(struct file * file, const char __user * userbuf, static ssize_t write(struct file *file, const char __user *userbuf,
size_t count, loff_t * off) size_t bytes, loff_t *off)
{ {
char *buffer = file->private_data; char *buffer = file->private_data;
struct dentry *dentry = file->f_path.dentry; struct dentry *dentry = file->f_path.dentry;
int size = dentry->d_inode->i_size; int size = dentry->d_inode->i_size;
loff_t offs = *off; loff_t offs = *off;
int count = min_t(size_t, bytes, PAGE_SIZE);
if (count > PAGE_SIZE)
count = PAGE_SIZE;
if (size) { if (size) {
if (offs > size) if (offs > size)
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册