From: Julia Lawall Date: Sat, 15 May 2010 21:19:30 +0000 (+0200) Subject: HID: Use kmemdup X-Git-Tag: v2.6.35-rc1~454^2~5^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1721a238ba5df9e870ed952464d38714261f5be9;p=platform%2Fkernel%2Flinux-3.10.git 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 --- diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index b9f99f9..c9eb2d0 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));