Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

V4L/DVB: drivers/media/video/uvc: 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/)

// <smpl>
@@
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);
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Julia Lawall and committed by
Mauro Carvalho Chehab
0b21d55f feda79bf

+2 -3
+2 -3
drivers/media/video/uvc/uvc_driver.c
··· 637 637 } 638 638 streaming->header.bControlSize = n; 639 639 640 - streaming->header.bmaControls = kmalloc(p*n, GFP_KERNEL); 640 + streaming->header.bmaControls = kmemdup(&buffer[size], p * n, 641 + GFP_KERNEL); 641 642 if (streaming->header.bmaControls == NULL) { 642 643 ret = -ENOMEM; 643 644 goto error; 644 645 } 645 - 646 - memcpy(streaming->header.bmaControls, &buffer[size], p*n); 647 646 648 647 buflen -= buffer[0]; 649 648 buffer += buffer[0];