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

V4L/DVB: drivers/media/video/gspca: 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
feda79bf 230b27cd

+1 -2
+1 -2
drivers/media/video/gspca/t613.c
··· 572 572 } else { 573 573 u8 *tmpbuf; 574 574 575 - tmpbuf = kmalloc(len, GFP_KERNEL); 575 + tmpbuf = kmemdup(buffer, len, GFP_KERNEL); 576 576 if (!tmpbuf) { 577 577 err("Out of memory"); 578 578 return; 579 579 } 580 - memcpy(tmpbuf, buffer, len); 581 580 usb_control_msg(gspca_dev->dev, 582 581 usb_sndctrlpipe(gspca_dev->dev, 0), 583 582 0,