Skip to contentSkip to conversation

net: usb: ch9200: use kmemdup instead of kmalloc + memcpy

PATCH In review Anup Limbu 3 participants 3 messages Nov 25, 2015 – Nov 30, 2015

Subsystems (3)
lore
Share & tools
lore

Anup Limbu

author
#0 lore raw

PATCH 1/1 net: usb: ch9200: use kmemdup instead of kmalloc + memcpy

replace kmalloc + memset with kmemdup

---
 drivers/net/usb/ch9200.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/usb/ch9200.c +1 -2
index 5e151e6..8a40202 100644
@@ -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,
Signature · 1 line
1.9.1
#1 lore raw
Quoted 15 lines · Anup Limbu

replace kmalloc + memset with kmemdup

---
 drivers/net/usb/ch9200.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/usb/ch9200.c +0 -0
index 5e151e6..8a40202 100644
@@ -155,12 +155,11 @@ static int control_write(struct usbnet *dev, unsigned char request,
 		   index, size);
 
 	if (data) {

drivers/net/usb/ch9200.c static int control_write(struct usbnet *dev, unsigned char request, · line 165

Quoted 10 lines
drivers/net/usb/ch9200.c +1 -2
-		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

maintainer
#2 lore raw
In reply to Anup Limbu

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

Quoted 3 lines

replace kmalloc + memset with kmemdup

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 [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html