From: Martyn Welch <martyn.welch@ge.com>
To: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>,
<linux-kernel@vger.kernel.org>, <devel@driverdev.osuosl.org>
Cc: Manohar Vanga <manohar.vanga@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCHv3 6/9] staging: vme_user: switch to returning -EFAULT on __copy_*_user errors
Date: Mon, 6 Jul 2015 13:51:18 +0100 [thread overview]
Message-ID: <559A79C6.4020601@ge.com> (raw)
In-Reply-To: <1435351184-19158-7-git-send-email-dmitry.kalinkin@gmail.com>
On 26/06/15 21:39, Dmitry Kalinkin wrote:
> Signed-off-by: Dmitry Kalinkin <dmitry.kalinkin@gmail.com>
> ---
> 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 a2345db..ef876a4 100644
> --- a/drivers/staging/vme/devices/vme_user.c
> +++ b/drivers/staging/vme/devices/vme_user.c
> @@ -123,7 +123,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)
> @@ -135,13 +134,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;
Does __copy_to_user() not return the number of bytes still to be copied?
The above seems to add the assumption that __copy_to_user()
can't return part way through a copy.
> }
> @@ -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,
> 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;
>
Same here.
> copied = vme_master_write(image[minor].resource, image[minor].kern_buf,
> - copied, *ppos);
> + count, *ppos);
>
> return copied;
> }
> @@ -172,38 +161,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 -EFAULT;
>
Ditto.
> - 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 -EFAULT;
>
And here.
> - 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,
>
--
Martyn Welch (Lead Software Engineer) | Registered in England and Wales
GE Intelligent Platforms | (3828642) at 100 Barbirolli Square
T +44(0)1327322748 | Manchester, M2 3AB
E martyn.welch@ge.com | VAT:GB 927559189
next prev parent reply other threads:[~2015-07-06 12:51 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-23 12:42 [PATCH 0/9] vme_user checkpatch fixes and read()/write() rework Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 1/9] staging: vme_user: fix code alignment Dmitry Kalinkin
2015-06-23 13:21 ` Frans Klaver
2015-06-23 13:44 ` Dmitry Kalinkin
2015-06-23 13:43 ` Frans Klaver
2015-06-23 12:42 ` [PATCH 2/9] staging: vme_user: fix blank lines Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 3/9] staging: vme_user: fix NULL comparison style Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 4/9] staging: vme_user: fix kmalloc style Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 5/9] staging: vme_user: allow large read()/write() Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 6/9] staging: vme_user: return -EFAULT on __copy_*_user errors Dmitry Kalinkin
2015-06-23 13:51 ` Dan Carpenter
2015-06-23 14:13 ` Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 0/9] vme_user checkpatch fixes and read()/write() rework Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 1/9] staging: vme_user: fix code alignment Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 2/9] staging: vme_user: fix blank lines Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 3/9] staging: vme_user: fix NULL comparison style Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 4/9] staging: vme_user: fix kmalloc style Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 5/9] staging: vme_user: allow large read()/write() Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 6/9] staging: vme_user: return -EFAULT on __copy_*_user errors Dmitry Kalinkin
2015-06-25 11:27 ` Sudip Mukherjee
2015-06-25 12:05 ` Dmitry Kalinkin
2015-06-25 17:05 ` Dmitry Kalinkin
2015-07-06 12:42 ` Martyn Welch
2015-06-23 16:03 ` [PATCHv2 7/9] staging: vme_user: remove unused variable Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 8/9] staging: vme_user: remove distracting comment Dmitry Kalinkin
2015-06-23 16:03 ` [PATCHv2 9/9] staging: vme_user: remove okcount variable Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 0/9] vme_user checkpatch fixes and read()/write() rework Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 1/9] staging: vme_user: fix code alignment Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 2/9] staging: vme_user: fix blank lines Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 3/9] staging: vme_user: fix NULL comparison style Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 4/9] staging: vme_user: fix kmalloc style Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 5/9] staging: vme_user: allow large read()/write() Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 6/9] staging: vme_user: switch to returning -EFAULT on __copy_*_user errors Dmitry Kalinkin
2015-07-06 12:51 ` Martyn Welch [this message]
2015-07-06 13:10 ` Dmitry Kalinkin
2015-07-06 13:51 ` Martyn Welch
2015-06-26 20:39 ` [PATCHv3 7/9] staging: vme_user: remove unused variable Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 8/9] staging: vme_user: remove distracting comment Dmitry Kalinkin
2015-06-26 20:39 ` [PATCHv3 9/9] staging: vme_user: remove okcount variable Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 7/9] staging: vme_user: remove unused variable Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 8/9] staging: vme_user: remove distracting comment Dmitry Kalinkin
2015-06-23 12:42 ` [PATCH 9/9] staging: vme_user: remove okcount variable Dmitry Kalinkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=559A79C6.4020601@ge.com \
--to=martyn.welch@ge.com \
--cc=devel@driverdev.osuosl.org \
--cc=dmitry.kalinkin@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manohar.vanga@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.