Thread (4 messages) 4 messages, 3 authors, 2014-05-26
STALE4396d

[PATCH 16/18] HID: uhid: Use kmemdup instead of kmalloc + memcpy

From: Benoit Taine <hidden>
Date: 2014-05-26 15:24:07
Also in: kernel-janitors, lkml
Subsystem: hid core layer, the rest, uhid userspace hid io driver · Maintainers: Jiri Kosina, Benjamin Tissoires, Linus Torvalds, David Rheinsberg

This issue was reported by coccicheck using the semantic patch 
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <redacted>
---
Tested by compilation without errors.

 drivers/hid/uhid.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
index 0d078c3..0cb92e3 100644
--- a/drivers/hid/uhid.c
+++ b/drivers/hid/uhid.c
@@ -441,12 +441,11 @@ static int uhid_dev_create2(struct uhid_device *uhid,
 	if (uhid->rd_size <= 0 || uhid->rd_size > HID_MAX_DESCRIPTOR_SIZE)
 		return -EINVAL;
 
-	uhid->rd_data = kmalloc(uhid->rd_size, GFP_KERNEL);
+	uhid->rd_data = kmemdup(ev->u.create2.rd_data, uhid->rd_size,
+				GFP_KERNEL);
 	if (!uhid->rd_data)
 		return -ENOMEM;
 
-	memcpy(uhid->rd_data, ev->u.create2.rd_data, uhid->rd_size);
-
 	hid = hid_allocate_device();
 	if (IS_ERR(hid)) {
 		ret = PTR_ERR(hid);
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help