2015-11-25 10:07:58

by Anup Limbu

[permalink] [raw]
Subject: [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy

replace kmalloc + memset with kmemdup

Signed-off-by: Anup Limbu <[email protected]>
---
drivers/net/usb/ch9200.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
index 5e151e6..8a40202 100644
--- a/drivers/net/usb/ch9200.c
+++ b/drivers/net/usb/ch9200.c
@@ -155,12 +155,11 @@ static int control_write(struct usbnet *dev, unsigned char request,
index, size);

if (data) {
- buf = kmalloc(size, GFP_KERNEL);
+ buf = kmemdup(data, size, GFP_KERNEL);
if (!buf) {
err = -ENOMEM;
goto err_out;
}
- memcpy(buf, data, size);
}

err = usb_control_msg(dev->udev,
--
1.9.1


2015-11-25 16:19:32

by Bjørn Mork

[permalink] [raw]
Subject: Re: [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy

Anup Limbu <[email protected]> writes:

> replace kmalloc + memset with kmemdup
>
> Signed-off-by: Anup Limbu <[email protected]>
> ---
> drivers/net/usb/ch9200.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/drivers/net/usb/ch9200.c b/drivers/net/usb/ch9200.c
> index 5e151e6..8a40202 100644
> --- a/drivers/net/usb/ch9200.c
> +++ b/drivers/net/usb/ch9200.c
> @@ -155,12 +155,11 @@ static int control_write(struct usbnet *dev, unsigned char request,
> index, size);
>
> if (data) {
> - buf = kmalloc(size, GFP_KERNEL);
> + buf = kmemdup(data, size, GFP_KERNEL);
> if (!buf) {
> err = -ENOMEM;
> goto err_out;
> }
> - memcpy(buf, data, size);
> }
>
> err = usb_control_msg(dev->udev,


Would it be better to replace control_read() and control_write() with
the usbnet_read_cmd() and usbnet_write_cmd() if you are going to clean
this up?



Bjørn

2015-11-30 03:40:35

by David Miller

[permalink] [raw]
Subject: Re: [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy

From: Anup Limbu <[email protected]>
Date: Wed, 25 Nov 2015 15:37:21 +0530

> replace kmalloc + memset with kmemdup
>
> Signed-off-by: Anup Limbu <[email protected]>

I agree with Bjorn that this microturfing cleanup misses
the real higher level opportunity to use the usbnet_read_cmd()
and usbnet_write_cmd() helpers that already exist.

Over time I am getting more and more weary of laser focused
microscopic cleanups.