From: Dan Carpenter <dan.carpenter@oracle.com>
To: Todd Kjos <tkjos@android.com>
Cc: tkjos@google.com, gregkh@linuxfoundation.org, arve@android.com,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
maco@google.com, joel@joelfernandes.org, kernel-team@android.com
Subject: Re: [PATCH 1/7] binder: create userspace-to-binder-buffer copy function
Date: Tue, 29 Jan 2019 11:12:18 +0300 [thread overview]
Message-ID: <20190129081218.GL1795@kadam> (raw)
In-Reply-To: <20190129004934.85885-2-tkjos@google.com>
On Mon, Jan 28, 2019 at 04:49:28PM -0800, Todd Kjos wrote:
> +/**
> + * binder_alloc_copy_user_to_buffer() - copy src user to tgt user
> + * @alloc: binder_alloc for this proc
> + * @buffer: binder buffer to be accessed
> + * @buffer_offset: offset into @buffer data
> + * @from: userspace pointer to source buffer
> + * @bytes: bytes to copy
> + *
> + * Copy bytes from source userspace to target buffer.
> + *
> + * Return: bytes remaining to be copied
> + */
> +unsigned long
> +binder_alloc_copy_user_to_buffer(struct binder_alloc *alloc,
> + struct binder_buffer *buffer,
> + binder_size_t buffer_offset,
> + const void __user *from,
> + size_t bytes)
> +{
> + if (!check_buffer(alloc, buffer, buffer_offset, bytes))
> + return bytes;
> +
> + while (bytes) {
> + unsigned long size;
> + unsigned long ret;
> + struct page *page;
> + pgoff_t pgoff;
> + void *kptr;
> +
> + page = binder_alloc_get_page(alloc, buffer,
> + buffer_offset, &pgoff);
> + size = min(bytes, (size_t)(PAGE_SIZE - pgoff));
This code has so much more casting than necessary. To me casting says
that we haven't got the types correct or something. I've just pulled
this function out as an example really, but none of the casts here are
required... This could just be:
size = min(bytes, PAGE_SIZE - pgoff);
Btw, if you really need to do a cast inside a min() (you don't in this
cast) then use min_t().
> + kptr = (void *)((uintptr_t)kmap(page) + pgoff);
This would be a lot cleaner as:
kptr = kmap(page) + pgoff;
> + ret = copy_from_user(kptr, (const void __user *)(uintptr_t)from,
> + size);
Remove the cast:
ret = copy_from_user(kptr, from, size);
> + kunmap(page);
> + if (ret)
> + return bytes - size + ret;
> + bytes -= size;
> + from = (void __user *)(uintptr_t)from + size;
Remove the cast:
from += size;
> + buffer_offset += size;
> + }
> + return 0;
> +}
regards,
dan carpenter
next prev parent reply other threads:[~2019-01-29 8:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-29 0:49 [PATCH 0/7] binder: eliminate use of vmalloc space for binder buffers Todd Kjos
2019-01-29 0:49 ` [PATCH 1/7] binder: create userspace-to-binder-buffer copy function Todd Kjos
2019-01-29 8:12 ` Dan Carpenter [this message]
2019-01-30 0:32 ` Todd Kjos
2019-01-30 5:12 ` Dan Carpenter
2019-01-29 0:49 ` [PATCH 2/7] binder: add functions to copy to/from binder buffers Todd Kjos
2019-01-29 0:49 ` [PATCH 3/7] binder: add function to copy binder object from buffer Todd Kjos
2019-01-29 0:49 ` [PATCH 4/7] binder: avoid kernel vm_area for buffer fixups Todd Kjos
2019-01-29 0:49 ` [PATCH 5/7] binder: remove kernel vm_area for buffer space Todd Kjos
2019-01-29 0:49 ` [PATCH 6/7] binder: remove user_buffer_offset Todd Kjos
2019-01-29 0:49 ` [PATCH 7/7] binder: use userspace pointer as base of buffer space Todd Kjos
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=20190129081218.GL1795@kadam \
--to=dan.carpenter@oracle.com \
--cc=arve@android.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=joel@joelfernandes.org \
--cc=kernel-team@android.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maco@google.com \
--cc=tkjos@android.com \
--cc=tkjos@google.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.