Skip to content

Commit

Permalink
HID: uhid: Use kmemdup instead of kmalloc + memcpy
Browse files Browse the repository at this point in the history
This issue was reported by coccicheck using the semantic patch
at scripts/coccinelle/api/memdup.cocci

Signed-off-by: Benoit Taine <benoit.taine@lip6.fr>
Reviewed-by: David Herrmann <dh.herrmann@gmail.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Benoit Taine authored and Jiri Kosina committed May 26, 2014
1 parent 37c492c commit 662d4ce
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/hid/uhid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 662d4ce

Please sign in to comment.