2013-03-10 22:58:19

by Alexandru Gheorghiu

[permalink] [raw]
Subject: [PATCH] fs: pstore: Replaced calls to kmalloc and memcpy with kmemdup

Replaced calls to kmalloc and memcpy with a single call to kmemdup.
This patch was found using coccicheck.

Signed-off-by: Alexandru Gheorghiu <[email protected]>
---
fs/pstore/ram.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 288f068..38babb3 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -156,10 +156,9 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
time->tv_nsec = 0;

size = persistent_ram_old_size(prz);
- *buf = kmalloc(size, GFP_KERNEL);
+ *buf = kmemdup(persistent_ram_old(prz), size, GFP_KERNEL);
if (*buf == NULL)
return -ENOMEM;
- memcpy(*buf, persistent_ram_old(prz), size);

return size;
}
--
1.7.9.5


2013-03-10 23:23:04

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH] fs: pstore: Replaced calls to kmalloc and memcpy with kmemdup

On Sat, Mar 9, 2013 at 3:57 AM, Alexandru Gheorghiu
<[email protected]> wrote:
> Replaced calls to kmalloc and memcpy with a single call to kmemdup.
> This patch was found using coccicheck.
>
> Signed-off-by: Alexandru Gheorghiu <[email protected]>
> ---
> fs/pstore/ram.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
> index 288f068..38babb3 100644
> --- a/fs/pstore/ram.c
> +++ b/fs/pstore/ram.c
> @@ -156,10 +156,9 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
> time->tv_nsec = 0;
>
> size = persistent_ram_old_size(prz);
> - *buf = kmalloc(size, GFP_KERNEL);
> + *buf = kmemdup(persistent_ram_old(prz), size, GFP_KERNEL);
> if (*buf == NULL)
> return -ENOMEM;
> - memcpy(*buf, persistent_ram_old(prz), size);
>
> return size;
> }

Looks fine to me. Thanks!

Acked-by: Kees Cook <[email protected]>

-Kees

--
Kees Cook
Chrome OS Security

2013-03-19 02:45:17

by Anton Vorontsov

[permalink] [raw]
Subject: Re: [PATCH] fs: pstore: Replaced calls to kmalloc and memcpy with kmemdup

On Sun, Mar 10, 2013 at 04:23:01PM -0700, Kees Cook wrote:
> On Sat, Mar 9, 2013 at 3:57 AM, Alexandru Gheorghiu
> <[email protected]> wrote:
> > Replaced calls to kmalloc and memcpy with a single call to kmemdup.
> > This patch was found using coccicheck.
> >
> > Signed-off-by: Alexandru Gheorghiu <[email protected]>
[...]
> Looks fine to me. Thanks!
>
> Acked-by: Kees Cook <[email protected]>

Applied to linux-pstore.git, thanks a lot!

Anton