NFSD: Use simple_read_from_buffer for coping data to userspace
authorKinglong Mee <kinglongmee@gmail.com>
Tue, 8 Apr 2014 05:04:01 +0000 (13:04 +0800)
committerJ. Bruce Fields <bfields@redhat.com>
Thu, 8 May 2014 18:59:52 +0000 (14:59 -0400)
Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
fs/nfsd/fault_inject.c

index d620e7f8142903feebabcb2c3cefdf6a5ea2f1de..2ed05c3cd43dee7459b0bec809a1b61800aeebe3 100644 (file)
@@ -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,