Commit 7c78e0cd authored by Dmitry Kalinkin's avatar Dmitry Kalinkin Committed by Greg Kroah-Hartman

staging: vme_user: switch to returning -EFAULT on __copy_*_user errors

Signed-off-by: default avatarDmitry Kalinkin <dmitry.kalinkin@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 8e4d138c
...@@ -123,7 +123,6 @@ struct vme_user_vma_priv { ...@@ -123,7 +123,6 @@ struct vme_user_vma_priv {
static ssize_t resource_to_user(int minor, char __user *buf, size_t count, static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
loff_t *ppos) loff_t *ppos)
{ {
ssize_t retval;
ssize_t copied = 0; ssize_t copied = 0;
if (count > image[minor].size_buf) if (count > image[minor].size_buf)
...@@ -135,13 +134,8 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count, ...@@ -135,13 +134,8 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
if (copied < 0) if (copied < 0)
return (int)copied; return (int)copied;
retval = __copy_to_user(buf, image[minor].kern_buf, if (__copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied))
(unsigned long)copied); return -EFAULT;
if (retval != 0) {
copied = (copied - retval);
pr_info("User copy failed\n");
return -EINVAL;
}
return copied; return copied;
} }
...@@ -149,21 +143,16 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count, ...@@ -149,21 +143,16 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count,
static ssize_t resource_from_user(unsigned int minor, const char __user *buf, static ssize_t resource_from_user(unsigned int minor, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
ssize_t retval;
ssize_t copied = 0; ssize_t copied = 0;
if (count > image[minor].size_buf) if (count > image[minor].size_buf)
count = image[minor].size_buf; count = image[minor].size_buf;
retval = __copy_from_user(image[minor].kern_buf, buf, if (__copy_from_user(image[minor].kern_buf, buf, (unsigned long)count))
(unsigned long)count); return -EFAULT;
if (retval != 0)
copied = (copied - retval);
else
copied = count;
copied = vme_master_write(image[minor].resource, image[minor].kern_buf, copied = vme_master_write(image[minor].resource, image[minor].kern_buf,
copied, *ppos); count, *ppos);
return copied; return copied;
} }
...@@ -172,38 +161,24 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf, ...@@ -172,38 +161,24 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
void *image_ptr; void *image_ptr;
ssize_t retval;
image_ptr = image[minor].kern_buf + *ppos; image_ptr = image[minor].kern_buf + *ppos;
if (__copy_to_user(buf, image_ptr, (unsigned long)count))
return -EFAULT;
retval = __copy_to_user(buf, image_ptr, (unsigned long)count); return count;
if (retval != 0) {
retval = (count - retval);
pr_warn("Partial copy to userspace\n");
} else
retval = count;
/* Return number of bytes successfully read */
return retval;
} }
static ssize_t buffer_from_user(unsigned int minor, const char __user *buf, static ssize_t buffer_from_user(unsigned int minor, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
void *image_ptr; void *image_ptr;
size_t retval;
image_ptr = image[minor].kern_buf + *ppos; image_ptr = image[minor].kern_buf + *ppos;
if (__copy_from_user(image_ptr, buf, (unsigned long)count))
return -EFAULT;
retval = __copy_from_user(image_ptr, buf, (unsigned long)count); return count;
if (retval != 0) {
retval = (count - retval);
pr_warn("Partial copy to userspace\n");
} else
retval = count;
/* Return number of bytes successfully read */
return retval;
} }
static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count, static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,
......
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