Commit 7828466c authored by Slark Xiao's avatar Slark Xiao Committed by Johan Hovold

USB: serial: use kmemdup instead of kmalloc + memcpy

For code neat purpose, we can use kmemdup to replace
kmalloc + memcpy.
Signed-off-by: default avatarSlark Xiao <slark_xiao@163.com>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
parent a111daf0
...@@ -988,7 +988,7 @@ static int garmin_write_bulk(struct usb_serial_port *port, ...@@ -988,7 +988,7 @@ static int garmin_write_bulk(struct usb_serial_port *port,
garmin_data_p->flags &= ~FLAGS_DROP_DATA; garmin_data_p->flags &= ~FLAGS_DROP_DATA;
spin_unlock_irqrestore(&garmin_data_p->lock, flags); spin_unlock_irqrestore(&garmin_data_p->lock, flags);
buffer = kmalloc(count, GFP_ATOMIC); buffer = kmemdup(buf, count, GFP_ATOMIC);
if (!buffer) if (!buffer)
return -ENOMEM; return -ENOMEM;
...@@ -998,8 +998,6 @@ static int garmin_write_bulk(struct usb_serial_port *port, ...@@ -998,8 +998,6 @@ static int garmin_write_bulk(struct usb_serial_port *port,
return -ENOMEM; return -ENOMEM;
} }
memcpy(buffer, buf, count);
usb_serial_debug_data(&port->dev, __func__, count, buffer); usb_serial_debug_data(&port->dev, __func__, count, buffer);
usb_fill_bulk_urb(urb, serial->dev, usb_fill_bulk_urb(urb, serial->dev,
......
...@@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, ...@@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
priv->outstanding_bytes += count; priv->outstanding_bytes += count;
spin_unlock_irqrestore(&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
buffer = kmalloc(count, GFP_ATOMIC); buffer = kmemdup(buf, count, GFP_ATOMIC);
if (!buffer) if (!buffer)
goto error_no_buffer; goto error_no_buffer;
...@@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port, ...@@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
if (!urb) if (!urb)
goto error_no_urb; goto error_no_urb;
memcpy(buffer, buf, count);
usb_serial_debug_data(&port->dev, __func__, count, buffer); usb_serial_debug_data(&port->dev, __func__, count, buffer);
/* The connected devices do not have a bulk write endpoint, /* The connected devices do not have a bulk write endpoint,
......
...@@ -453,7 +453,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, ...@@ -453,7 +453,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
goto error_simple; goto error_simple;
} }
buffer = kmalloc(writesize, GFP_ATOMIC); buffer = kmemdup(buf, writesize, GFP_ATOMIC);
if (!buffer) { if (!buffer) {
retval = -ENOMEM; retval = -ENOMEM;
goto error_no_buffer; goto error_no_buffer;
...@@ -465,8 +465,6 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port, ...@@ -465,8 +465,6 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
goto error_no_urb; goto error_no_urb;
} }
memcpy(buffer, buf, writesize);
usb_serial_debug_data(&port->dev, __func__, writesize, buffer); usb_serial_debug_data(&port->dev, __func__, writesize, buffer);
usb_fill_bulk_urb(urb, serial->dev, usb_fill_bulk_urb(urb, serial->dev,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment