Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932781AbbFWMna (ORCPT ); Tue, 23 Jun 2015 08:43:30 -0400 Received: from mail-la0-f41.google.com ([209.85.215.41]:33112 "EHLO mail-la0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932530AbbFWMnM (ORCPT ); Tue, 23 Jun 2015 08:43:12 -0400 From: Dmitry Kalinkin To: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org Cc: Martyn Welch , Manohar Vanga , Greg Kroah-Hartman , Dmitry Kalinkin Subject: [PATCH 6/9] staging: vme_user: return -EFAULT on __copy_*_user errors Date: Tue, 23 Jun 2015 15:42:30 +0300 Message-Id: <1435063353-25914-7-git-send-email-dmitry.kalinkin@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1435063353-25914-1-git-send-email-dmitry.kalinkin@gmail.com> References: <1435063353-25914-1-git-send-email-dmitry.kalinkin@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3272 Lines: 111 Signed-off-by: Dmitry Kalinkin --- drivers/staging/vme/devices/vme_user.c | 47 ++++++++-------------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/drivers/staging/vme/devices/vme_user.c b/drivers/staging/vme/devices/vme_user.c index 52cd638..85eb6ee 100644 --- a/drivers/staging/vme/devices/vme_user.c +++ b/drivers/staging/vme/devices/vme_user.c @@ -129,7 +129,6 @@ struct vme_user_vma_priv { static ssize_t resource_to_user(int minor, char __user *buf, size_t count, loff_t *ppos) { - ssize_t retval; ssize_t copied = 0; if (count > image[minor].size_buf) @@ -141,13 +140,8 @@ static ssize_t resource_to_user(int minor, char __user *buf, size_t count, if (copied < 0) return (int)copied; - retval = __copy_to_user(buf, image[minor].kern_buf, - (unsigned long)copied); - if (retval != 0) { - copied = (copied - retval); - pr_info("User copy failed\n"); - return -EINVAL; - } + if (__copy_to_user(buf, image[minor].kern_buf, (unsigned long)copied)) + return -EFAULT; return copied; } @@ -155,21 +149,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, size_t count, loff_t *ppos) { - ssize_t retval; ssize_t copied = 0; if (count > image[minor].size_buf) count = image[minor].size_buf; - retval = __copy_from_user(image[minor].kern_buf, buf, - (unsigned long)count); - if (retval != 0) - copied = (copied - retval); - else - copied = count; + if (__copy_from_user(image[minor].kern_buf, buf, (unsigned long)count)) + return -EFAULT; copied = vme_master_write(image[minor].resource, image[minor].kern_buf, - copied, *ppos); + count, *ppos); return copied; } @@ -178,38 +167,24 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf, size_t count, loff_t *ppos) { void *image_ptr; - ssize_t retval; image_ptr = image[minor].kern_buf + *ppos; + if (__copy_to_user(buf, image_ptr, (unsigned long)count)) + return -EINVAL; - retval = __copy_to_user(buf, image_ptr, (unsigned long)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; + return count; } static ssize_t buffer_from_user(unsigned int minor, const char __user *buf, size_t count, loff_t *ppos) { void *image_ptr; - size_t retval; image_ptr = image[minor].kern_buf + *ppos; + if (__copy_from_user(image_ptr, buf, (unsigned long)count)) + return -EINVAL; - retval = __copy_from_user(image_ptr, buf, (unsigned long)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; + return count; } static ssize_t vme_user_read(struct file *file, char __user *buf, size_t count, -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/