netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy
@ 2015-11-25 10:07 Anup Limbu
  2015-11-25 16:19 ` Bjørn Mork
       [not found] ` <1448446041-15663-1-git-send-email-anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Anup Limbu @ 2015-11-25 10:07 UTC (permalink / raw)
  To: davem, mjg59, tklauser, linux-usb, netdev, linux-kernel; +Cc: Anup Limbu

replace kmalloc + memset with kmemdup

Signed-off-by: Anup Limbu <anuplimbu14@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy
  2015-11-25 10:07 [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy Anup Limbu
@ 2015-11-25 16:19 ` Bjørn Mork
       [not found] ` <1448446041-15663-1-git-send-email-anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Bjørn Mork @ 2015-11-25 16:19 UTC (permalink / raw)
  To: Anup Limbu; +Cc: davem, mjg59, tklauser, linux-usb, netdev, linux-kernel

Anup Limbu <anuplimbu14@gmail.com> writes:

> replace kmalloc + memset with kmemdup
>
> Signed-off-by: Anup Limbu <anuplimbu14@gmail.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy
       [not found] ` <1448446041-15663-1-git-send-email-anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-11-30  3:40   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2015-11-30  3:40 UTC (permalink / raw)
  To: anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w
  Cc: mjg59-1xO5oi07KQx4cg9Nei1l7Q, tklauser-93Khv+1bN0NBDgjK7y7TUQ,
	linux-usb-u79uwXL29TY76Z2rM5mHXA, netdev-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Anup Limbu <anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Date: Wed, 25 Nov 2015 15:37:21 +0530

> replace kmalloc + memset with kmemdup
> 
> Signed-off-by: Anup Limbu <anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

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.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-30  3:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-25 10:07 [PATCH] net: usb: ch9200: use kmemdup instead of kmalloc + memcpy Anup Limbu
2015-11-25 16:19 ` Bjørn Mork
     [not found] ` <1448446041-15663-1-git-send-email-anuplimbu14-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-30  3:40   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).