From 1721a238ba5df9e870ed952464d38714261f5be9 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Sat, 15 May 2010 23:19:30 +0200 Subject: [PATCH] HID: Use kmemdup Use kmemdup when some other buffer is immediately copied into the allocated region. A simplified version of the semantic patch that makes this change is as follows: (http://coccinelle.lip6.fr/) // @@ expression from,to,size,flag; statement S; @@ - to = \(kmalloc\|kzalloc\)(size,flag); + to = kmemdup(from,size,flag); if (to==NULL || ...) S - memcpy(to, from, size); // Signed-off-by: Julia Lawall Signed-off-by: Jiri Kosina --- drivers/hid/hid-core.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index b9f99f9c4b2f..c9eb2d08f396 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -653,10 +653,9 @@ int hid_parse_report(struct hid_device *device, __u8 *start, if (device->driver->report_fixup) device->driver->report_fixup(device, start, size); - device->rdesc = kmalloc(size, GFP_KERNEL); + device->rdesc = kmemdup(start, size, GFP_KERNEL); if (device->rdesc == NULL) return -ENOMEM; - memcpy(device->rdesc, start, size); device->rsize = size; parser = vmalloc(sizeof(struct hid_parser)); -- 2.39.5