| From htejun@gmail.com Sun Apr 8 21:18:59 2007 |
| From: Tejun Heo <htejun@gmail.com> |
| Date: Mon, 9 Apr 2007 13:18:47 +0900 |
| Subject: sysfs: fix error handling in binattr write() |
| To: gregkh@suse.de, maneesh@in.ibm.com, dmitry.torokhov@gmail.com, cornelia.huck@de.ibm.com, oneukum@suse.de, rpurdie@rpsys.net, James.Bottomley@SteelEye.com, stern@rowland.harvard.edu, linux-kernel@vger.kernel.org, htejun@gmail.com |
| Cc: Tejun Heo <htejun@gmail.com> |
| Message-ID: <11760923271649-git-send-email-htejun@gmail.com> |
| |
| 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> |
| |
| --- |
| fs/sysfs/bin.c | 21 ++++++++------------- |
| 1 file changed, 8 insertions(+), 13 deletions(-) |
| |
| --- a/fs/sysfs/bin.c |
| +++ b/fs/sysfs/bin.c |
| @@ -33,16 +33,13 @@ fill_read(struct dentry *dentry, char *b |
| } |
| |
| 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; |
| struct dentry *dentry = file->f_path.dentry; |
| int size = dentry->d_inode->i_size; |
| loff_t offs = *off; |
| - int ret; |
| - |
| - if (count > PAGE_SIZE) |
| - count = PAGE_SIZE; |
| + int count = min_t(size_t, bytes, PAGE_SIZE); |
| |
| if (size) { |
| if (offs > size) |
| @@ -51,10 +48,9 @@ read(struct file * file, char __user * u |
| count = size - offs; |
| } |
| |
| - ret = fill_read(dentry, buffer, offs, count); |
| - if (ret < 0) |
| - return ret; |
| - count = ret; |
| + count = fill_read(dentry, buffer, offs, count); |
| + if (count < 0) |
| + return count; |
| |
| if (copy_to_user(userbuf, buffer, count)) |
| return -EFAULT; |
| @@ -78,16 +74,15 @@ flush_write(struct dentry *dentry, char |
| return attr->write(kobj, buffer, offset, count); |
| } |
| |
| -static ssize_t write(struct file * file, const char __user * userbuf, |
| - size_t count, loff_t * off) |
| +static ssize_t write(struct file *file, const char __user *userbuf, |
| + size_t bytes, loff_t *off) |
| { |
| char *buffer = file->private_data; |
| struct dentry *dentry = file->f_path.dentry; |
| int size = dentry->d_inode->i_size; |
| loff_t offs = *off; |
| + int count = min_t(size_t, bytes, PAGE_SIZE); |
| |
| - if (count > PAGE_SIZE) |
| - count = PAGE_SIZE; |
| if (size) { |
| if (offs > size) |
| return 0; |