diff mbox

NFSD: Use simple_read_from_buffer for coping data to userspace

Message ID 53438341.5090705@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kinglong Mee April 8, 2014, 5:04 a.m. UTC
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
---
 fs/nfsd/fault_inject.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)

 static ssize_t fault_inject_write(struct file *file, const char __user
*buf,

Comments

J. Bruce Fields May 8, 2014, 5:05 p.m. UTC | #1
Thanks, applying.--b.

On Tue, Apr 08, 2014 at 01:04:01PM +0800, Kinglong Mee wrote:
> Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
> ---
>  fs/nfsd/fault_inject.c | 15 ++-------------
>  1 file changed, 2 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
> index d620e7f..2ed05c3 100644
> --- a/fs/nfsd/fault_inject.c
> +++ b/fs/nfsd/fault_inject.c
> @@ -97,25 +97,14 @@ static ssize_t fault_inject_read(struct file *file,
> char __user *buf,
>  {
>  	static u64 val;
>  	char read_buf[25];
> -	size_t size, ret;
> +	size_t size;
>  	loff_t pos = *ppos;
> 
>  	if (!pos)
>  		nfsd_inject_get(file_inode(file)->i_private, &val);
>  	size = scnprintf(read_buf, sizeof(read_buf), "%llu\n", val);
> 
> -	if (pos < 0)
> -		return -EINVAL;
> -	if (pos >= size || !len)
> -		return 0;
> -	if (len > size - pos)
> -		len = size - pos;
> -	ret = copy_to_user(buf, read_buf + pos, len);
> -	if (ret == len)
> -		return -EFAULT;
> -	len -= ret;
> -	*ppos = pos + len;
> -	return len;
> +	return simple_read_from_buffer(buf, len, ppos, read_buf, size);
>  }
> 
>  static ssize_t fault_inject_write(struct file *file, const char __user
> *buf,
> -- 
> 1.9.0
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/nfsd/fault_inject.c b/fs/nfsd/fault_inject.c
index d620e7f..2ed05c3 100644
--- a/fs/nfsd/fault_inject.c
+++ b/fs/nfsd/fault_inject.c
@@ -97,25 +97,14 @@  static ssize_t fault_inject_read(struct file *file,
char __user *buf,
 {
 	static u64 val;
 	char read_buf[25];
-	size_t size, ret;
+	size_t size;
 	loff_t pos = *ppos;

 	if (!pos)
 		nfsd_inject_get(file_inode(file)->i_private, &val);
 	size = scnprintf(read_buf, sizeof(read_buf), "%llu\n", val);

-	if (pos < 0)
-		return -EINVAL;
-	if (pos >= size || !len)
-		return 0;
-	if (len > size - pos)
-		len = size - pos;
-	ret = copy_to_user(buf, read_buf + pos, len);
-	if (ret == len)
-		return -EFAULT;
-	len -= ret;
-	*ppos = pos + len;
-	return len;
+	return simple_read_from_buffer(buf, len, ppos, read_buf, size);
 }