Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Signed-off-by: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dmitry Kalinkin and committed by
Greg Kroah-Hartman
7c78e0cd 8e4d138c

+11 -36
+11 -36
drivers/staging/vme/devices/vme_user.c
··· 123 123 static ssize_t resource_to_user(int minor, char __user *buf, size_t count, 124 124 loff_t *ppos) 125 125 { 126 - ssize_t retval; 127 126 ssize_t copied = 0; 128 127 129 128 if (count > image[minor].size_buf) ··· 134 135 if (copied < 0) 135 136 return (int)copied; 136 137 137 - retval = __copy_to_user(buf, image[minor].kern_buf, 138 - (unsigned long)copied); 139 - if (retval != 0) { 140 - copied = (copied - retval); 141 - pr_info("User copy failed\n"); 142 - return -EINVAL; 143 - } 138 + if (__copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied)) 139 + return -EFAULT; 144 140 145 141 return copied; 146 142 } ··· 143 149 static ssize_t resource_from_user(unsigned int minor, const char __user *buf, 144 150 size_t count, loff_t *ppos) 145 151 { 146 - ssize_t retval; 147 152 ssize_t copied = 0; 148 153 149 154 if (count > image[minor].size_buf) 150 155 count = image[minor].size_buf; 151 156 152 - retval = __copy_from_user(image[minor].kern_buf, buf, 153 - (unsigned long)count); 154 - if (retval != 0) 155 - copied = (copied - retval); 156 - else 157 - copied = count; 157 + if (__copy_from_user(image[minor].kern_buf, buf, (unsigned long)count)) 158 + return -EFAULT; 158 159 159 160 copied = vme_master_write(image[minor].resource, image[minor].kern_buf, 160 - copied, *ppos); 161 + count, *ppos); 161 162 162 163 return copied; 163 164 } ··· 161 172 size_t count, loff_t *ppos) 162 173 { 163 174 void *image_ptr; 164 - ssize_t retval; 165 175 166 176 image_ptr = image[minor].kern_buf + *ppos; 177 + if (__copy_to_user(buf, image_ptr, (unsigned long)count)) 178 + return -EFAULT; 167 179 168 - retval = __copy_to_user(buf, image_ptr, (unsigned long)count); 169 - if (retval != 0) { 170 - retval = (count - retval); 171 - pr_warn("Partial copy to userspace\n"); 172 - } else 173 - retval = count; 174 - 175 - /* Return number of bytes successfully read */ 176 - return retval; 180 + return count; 177 181 } 178 182 179 183 static ssize_t buffer_from_user(unsigned int minor, const char __user *buf, 180 184 size_t count, loff_t *ppos) 181 185 { 182 186 void *image_ptr; 183 - size_t retval; 184 187 185 188 image_ptr = image[minor].kern_buf + *ppos; 189 + if (__copy_from_user(image_ptr, buf, (unsigned long)count)) 190 + return -EFAULT; 186 191 187 - retval = __copy_from_user(image_ptr, buf, (unsigned long)count); 188 - if (retval != 0) { 189 - retval = (count - retval); 190 - pr_warn("Partial copy to userspace\n"); 191 - } else 192 - retval = count; 193 - 194 - /* Return number of bytes successfully read */ 195 - return retval; 192 + return count; 196 193 } 197 194 198 195 static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count,