Skip to contentSkip to conversation

fs: pstore: Replaced calls to kmalloc and memcpy with kmemdup

PATCH Applied Alexandru Gheorghiu 3 participants 3 messages Mar 10, 2013 – Mar 19, 2013 Pstore filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 fs/pstore/ram.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/pstore/ram.c +1 -2
index 288f068..38babb3 100644
@@ -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;
 }
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 14 lines · Alexandru Gheorghiu

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

---
 fs/pstore/ram.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
fs/pstore/ram.c +0 -0
index 288f068..38babb3 100644
@@ -156,10 +156,9 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
        time->tv_nsec = 0;

fs/pstore/ram.c static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, · line 164

Quoted 10 lines
fs/pstore/ram.c +1 -2
 
        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!

-Kees

Signature · 2 lines
Kees Cook
Chrome OS Security