lkml.org 
[lkml]   [2017]   [Jun]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] pstore: use memdup_user
On Fri, Apr 28, 2017 at 6:45 PM, Geliang Tang <geliangtang@gmail.com> wrote:
> Use memdup_user() helper instead of open-coding to simplify the code.
>
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>

Thanks! Applied for -next.

-Kees

> ---
> fs/pstore/platform.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 43b3ca5..903e0fe 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
> @@ -640,19 +640,16 @@ static int pstore_write_user_compat(struct pstore_record *record,
> if (record->buf)
> return -EINVAL;
>
> - record->buf = kmalloc(record->size, GFP_KERNEL);
> - if (!record->buf)
> - return -ENOMEM;
> -
> - if (unlikely(copy_from_user(record->buf, buf, record->size))) {
> - ret = -EFAULT;
> + record->buf = memdup_user(buf, record->size);
> + if (unlikely(IS_ERR(record->buf))) {
> + ret = PTR_ERR(record->buf);
> goto out;
> }
>
> ret = record->psi->write(record);
>
> -out:
> kfree(record->buf);
> +out:
> record->buf = NULL;
>
> return unlikely(ret < 0) ? ret : record->size;
> --
> 2.9.3
>



--
Kees Cook
Pixel Security

\
 
 \ /
  Last update: 2017-06-28 02:08    [W:0.099 / U:6.976 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site