aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 14:45:13 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 19:09:03 -0400
commit93e3cd8270d036953120eca83610f95d3f7374c6 (patch)
tree8f5bc27cd1d7b28cafd4dd2bdbaabf0f16feb6c8
parent7a23ad44047b1084a032bc0d127fe08af024593a (diff)
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: Tejun Heo <htejun@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--fs/sysfs/bin.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index d3b9f5f07db1..606267a36275 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -33,16 +33,13 @@ fill_read(struct dentry *dentry, char *buffer, loff_t off, size_t count)
33} 33}
34 34
35static ssize_t 35static ssize_t
36read(struct file * file, char __user * userbuf, size_t count, loff_t * off) 36read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
37{ 37{
38 char *buffer = file->private_data; 38 char *buffer = file->private_data;
39 struct dentry *dentry = file->f_path.dentry; 39 struct dentry *dentry = file->f_path.dentry;
40 int size = dentry->d_inode->i_size; 40 int size = dentry->d_inode->i_size;
41 loff_t offs = *off; 41 loff_t offs = *off;
42 int ret; 42 int count = min_t(size_t, bytes, PAGE_SIZE);
43
44 if (count > PAGE_SIZE)
45 count = PAGE_SIZE;
46 43
47 if (size) { 44 if (size) {
48 if (offs > size) 45 if (offs > size)
@@ -51,15 +48,14 @@ read(struct file * file, char __user * userbuf, size_t count, loff_t * off)
51 count = size - offs; 48 count = size - offs;
52 } 49 }
53 50
54 ret = fill_read(dentry, buffer, offs, count); 51 count = fill_read(dentry, buffer, offs, count);
55 if (ret < 0) 52 if (count < 0)
56 return ret; 53 return count;
57 count = ret;
58 54
59 if (copy_to_user(userbuf, buffer, count)) 55 if (copy_to_user(userbuf, buffer, count))
60 return -EFAULT; 56 return -EFAULT;
61 57
62 pr_debug("offs = %lld, *off = %lld, count = %zd\n", offs, *off, count); 58 pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count);
63 59
64 *off = offs + count; 60 *off = offs + count;
65 61
@@ -78,16 +74,15 @@ flush_write(struct dentry *dentry, char *buffer, loff_t offset, size_t count)
78 return attr->write(kobj, buffer, offset, count); 74 return attr->write(kobj, buffer, offset, count);
79} 75}
80 76
81static ssize_t write(struct file * file, const char __user * userbuf, 77static ssize_t write(struct file *file, const char __user *userbuf,
82 size_t count, loff_t * off) 78 size_t bytes, loff_t *off)
83{ 79{
84 char *buffer = file->private_data; 80 char *buffer = file->private_data;
85 struct dentry *dentry = file->f_path.dentry; 81 struct dentry *dentry = file->f_path.dentry;
86 int size = dentry->d_inode->i_size; 82 int size = dentry->d_inode->i_size;
87 loff_t offs = *off; 83 loff_t offs = *off;
84 int count = min_t(size_t, bytes, PAGE_SIZE);
88 85
89 if (count > PAGE_SIZE)
90 count = PAGE_SIZE;
91 if (size) { 86 if (size) {
92 if (offs > size) 87 if (offs > size)
93 return 0; 88 return 0;