Commit 92f4c701 authored by Akinobu Mita's avatar Akinobu Mita Committed by Linus Torvalds

use simple_read_from_buffer() in fs/

Cleanup using simple_read_from_buffer() in binfmt_misc, configfs, and sysfs.

Cc: Greg Kroah-Hartman <gregkh@suse.de>
Cc: Joel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarAkinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 884c3d75
...@@ -675,19 +675,8 @@ static ssize_t ...@@ -675,19 +675,8 @@ static ssize_t
bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
{ {
char *s = enabled ? "enabled" : "disabled"; char *s = enabled ? "enabled" : "disabled";
int len = strlen(s);
loff_t pos = *ppos;
if (pos < 0) return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s));
return -EINVAL;
if (pos >= len)
return 0;
if (len < pos + nbytes)
nbytes = len - pos;
if (copy_to_user(buf, s + pos, nbytes))
return -EFAULT;
*ppos = pos + nbytes;
return nbytes;
} }
static ssize_t bm_status_write(struct file * file, const char __user * buffer, static ssize_t bm_status_write(struct file * file, const char __user * buffer,
......
...@@ -77,36 +77,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf ...@@ -77,36 +77,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
return ret; return ret;
} }
/**
* flush_read_buffer - push buffer to userspace.
* @buffer: data buffer for file.
* @userbuf: user-passed buffer.
* @count: number of bytes requested.
* @ppos: file position.
*
* Copy the buffer we filled in fill_read_buffer() to userspace.
* This is done at the reader's leisure, copying and advancing
* the amount they specify each time.
* This may be called continuously until the buffer is empty.
*/
static int flush_read_buffer(struct configfs_buffer * buffer, char __user * buf,
size_t count, loff_t * ppos)
{
int error;
if (*ppos > buffer->count)
return 0;
if (count > (buffer->count - *ppos))
count = buffer->count - *ppos;
error = copy_to_user(buf,buffer->page + *ppos,count);
if (!error)
*ppos += count;
return error ? -EFAULT : count;
}
/** /**
* configfs_read_file - read an attribute. * configfs_read_file - read an attribute.
* @file: file pointer. * @file: file pointer.
...@@ -139,7 +109,8 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp ...@@ -139,7 +109,8 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp
} }
pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
__FUNCTION__, count, *ppos, buffer->page); __FUNCTION__, count, *ppos, buffer->page);
retval = flush_read_buffer(buffer,buf,count,ppos); retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
buffer->count);
out: out:
up(&buffer->sem); up(&buffer->sem);
return retval; return retval;
......
...@@ -111,36 +111,6 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer ...@@ -111,36 +111,6 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
return ret; return ret;
} }
/**
* flush_read_buffer - push buffer to userspace.
* @buffer: data buffer for file.
* @buf: user-passed buffer.
* @count: number of bytes requested.
* @ppos: file position.
*
* Copy the buffer we filled in fill_read_buffer() to userspace.
* This is done at the reader's leisure, copying and advancing
* the amount they specify each time.
* This may be called continuously until the buffer is empty.
*/
static int flush_read_buffer(struct sysfs_buffer * buffer, char __user * buf,
size_t count, loff_t * ppos)
{
int error;
if (*ppos > buffer->count)
return 0;
if (count > (buffer->count - *ppos))
count = buffer->count - *ppos;
error = copy_to_user(buf,buffer->page + *ppos,count);
if (!error)
*ppos += count;
return error ? -EFAULT : count;
}
/** /**
* sysfs_read_file - read an attribute. * sysfs_read_file - read an attribute.
* @file: file pointer. * @file: file pointer.
...@@ -177,7 +147,8 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) ...@@ -177,7 +147,8 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
} }
pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
__FUNCTION__, count, *ppos, buffer->page); __FUNCTION__, count, *ppos, buffer->page);
retval = flush_read_buffer(buffer,buf,count,ppos); retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
buffer->count);
out: out:
up(&buffer->sem); up(&buffer->sem);
return retval; return retval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment