[media] media: usb: cpia2: Use kmemdup instead of kmalloc and memcpy
authorShyam Saini <mayhs11saini@gmail.com>
Fri, 23 Dec 2016 19:34:36 +0000 (17:34 -0200)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Tue, 31 Jan 2017 09:46:34 +0000 (07:46 -0200)
When some other buffer is immediately copied into allocated region.
Replace calls to kmalloc followed by a memcpy with a direct
call to kmemdup.

Signed-off-by: Shyam Saini <mayhs11saini@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/usb/cpia2/cpia2_usb.c

index 7a50662348f622e82e04e76aed9f57f42d8ab45e..1c7e16e5d88b53f0258fd2bcd749e10299945ec0 100644 (file)
@@ -547,12 +547,10 @@ static int write_packet(struct usb_device *udev,
        if (!registers || size <= 0)
                return -EINVAL;
 
-       buf = kmalloc(size, GFP_KERNEL);
+       buf = kmemdup(registers, size, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
 
-       memcpy(buf, registers, size);
-
        ret = usb_control_msg(udev,
                               usb_sndctrlpipe(udev, 0),
                               request,