USB: serial: cp210x: use kmemdup
authorMuhammad Falak R Wani <falakreyaz@gmail.com>
Thu, 19 May 2016 14:04:36 +0000 (19:34 +0530)
committerJohan Hovold <johan@kernel.org>
Fri, 15 Jul 2016 12:23:21 +0000 (14:23 +0200)
Use kmemdup when some other buffer is immediately copied into allocated
region. It replaces call to allocation followed by memcpy, by a single
call to kmemdup.

Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/cp210x.c

index 96a70789b4c215376914aaa1196785bff53ce312..4d6a5c672a3d1fd388c6f318c3000e1cfef354cb 100644 (file)
@@ -496,12 +496,10 @@ static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
        void *dmabuf;
        int result;
 
-       dmabuf = kmalloc(bufsize, GFP_KERNEL);
+       dmabuf = kmemdup(buf, bufsize, GFP_KERNEL);
        if (!dmabuf)
                return -ENOMEM;
 
-       memcpy(dmabuf, buf, bufsize);
-
        result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
                        req, REQTYPE_HOST_TO_INTERFACE, 0,
                        port_priv->bInterfaceNumber, dmabuf, bufsize,