* [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy
@ 2022-06-20 10:59 Slark Xiao
2022-06-20 13:10 ` Johan Hovold
0 siblings, 1 reply; 3+ messages in thread
From: Slark Xiao @ 2022-06-20 10:59 UTC (permalink / raw)
To: johan; +Cc: gregkh, linux-usb, linux-kernel, Slark Xiao
For code neat purpose, we can use kmemdup to replace
kmalloc + memcpy.
Signed-off-by: Slark Xiao <slark_xiao@163.com>
---
drivers/usb/serial/opticon.c | 4 +---
drivers/usb/serial/sierra.c | 4 +---
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index aed28c35caff..bca6766a63e6 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
priv->outstanding_bytes += count;
spin_unlock_irqrestore(&priv->lock, flags);
- buffer = kmalloc(count, GFP_ATOMIC);
+ buffer = kmemdup(buf, count, GFP_ATOMIC);
if (!buffer)
goto error_no_buffer;
@@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
if (!urb)
goto error_no_urb;
- memcpy(buffer, buf, count);
-
usb_serial_debug_data(&port->dev, __func__, count, buffer);
/* The connected devices do not have a bulk write endpoint,
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 9d56138133a9..865d1237d611 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -453,7 +453,7 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
goto error_simple;
}
- buffer = kmalloc(writesize, GFP_ATOMIC);
+ buffer = kmemdup(buf, writesize, GFP_ATOMIC);
if (!buffer) {
retval = -ENOMEM;
goto error_no_buffer;
@@ -465,8 +465,6 @@ static int sierra_write(struct tty_struct *tty, struct usb_serial_port *port,
goto error_no_urb;
}
- memcpy(buffer, buf, writesize);
-
usb_serial_debug_data(&port->dev, __func__, writesize, buffer);
usb_fill_bulk_urb(urb, serial->dev,
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy
2022-06-20 10:59 [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy Slark Xiao
@ 2022-06-20 13:10 ` Johan Hovold
2022-06-22 3:08 ` Slark Xiao
0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2022-06-20 13:10 UTC (permalink / raw)
To: Slark Xiao; +Cc: gregkh, linux-usb, linux-kernel
On Mon, Jun 20, 2022 at 06:59:39PM +0800, Slark Xiao wrote:
> For code neat purpose, we can use kmemdup to replace
> kmalloc + memcpy.
>
> Signed-off-by: Slark Xiao <slark_xiao@163.com>
> ---
> drivers/usb/serial/opticon.c | 4 +---
> drivers/usb/serial/sierra.c | 4 +---
> 2 files changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
> index aed28c35caff..bca6766a63e6 100644
> --- a/drivers/usb/serial/opticon.c
> +++ b/drivers/usb/serial/opticon.c
> @@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
> priv->outstanding_bytes += count;
> spin_unlock_irqrestore(&priv->lock, flags);
>
> - buffer = kmalloc(count, GFP_ATOMIC);
> + buffer = kmemdup(buf, count, GFP_ATOMIC);
> if (!buffer)
> goto error_no_buffer;
>
> @@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
> if (!urb)
> goto error_no_urb;
>
> - memcpy(buffer, buf, count);
> -
> usb_serial_debug_data(&port->dev, __func__, count, buffer);
>
> /* The connected devices do not have a bulk write endpoint,
Looks like we have the same pattern also in garmin_write_bulk(). Care to
include that one as well?
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re:Re: [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy
2022-06-20 13:10 ` Johan Hovold
@ 2022-06-22 3:08 ` Slark Xiao
0 siblings, 0 replies; 3+ messages in thread
From: Slark Xiao @ 2022-06-22 3:08 UTC (permalink / raw)
To: Johan Hovold; +Cc: gregkh, linux-usb, linux-kernel
At 2022-06-20 21:10:49, "Johan Hovold" <johan@kernel.org> wrote:
>On Mon, Jun 20, 2022 at 06:59:39PM +0800, Slark Xiao wrote:
>> For code neat purpose, we can use kmemdup to replace
>> kmalloc + memcpy.
>>
>> Signed-off-by: Slark Xiao <slark_xiao@163.com>
>> ---
>> drivers/usb/serial/opticon.c | 4 +---
>> drivers/usb/serial/sierra.c | 4 +---
>> 2 files changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
>> index aed28c35caff..bca6766a63e6 100644
>> --- a/drivers/usb/serial/opticon.c
>> +++ b/drivers/usb/serial/opticon.c
>> @@ -208,7 +208,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
>> priv->outstanding_bytes += count;
>> spin_unlock_irqrestore(&priv->lock, flags);
>>
>> - buffer = kmalloc(count, GFP_ATOMIC);
>> + buffer = kmemdup(buf, count, GFP_ATOMIC);
>> if (!buffer)
>> goto error_no_buffer;
>>
>> @@ -216,8 +216,6 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
>> if (!urb)
>> goto error_no_urb;
>>
>> - memcpy(buffer, buf, count);
>> -
>> usb_serial_debug_data(&port->dev, __func__, count, buffer);
>>
>> /* The connected devices do not have a bulk write endpoint,
>
>Looks like we have the same pattern also in garmin_write_bulk(). Care to
>include that one as well?
>
>Johan
Ok, I will add it into the patch as well in V2.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-22 3:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-20 10:59 [PATCH] USB: serial: use kmemdup instead of kmalloc + memcpy Slark Xiao
2022-06-20 13:10 ` Johan Hovold
2022-06-22 3:08 ` Slark Xiao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®