Skip to contentSkip to conversation

HID: roccat: Use kmemdup rather than duplicating its implementation

PATCH Applied Thomas Meyer 2 participants 2 messages Nov 17, 2011 – Nov 19, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 HID: roccat: Use kmemdup rather than duplicating its implementation

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

drivers/hid/hid-roccat-common.c 2011-11-08 10:45:42.781966362 +0100 renamed from drivers/hid/hid-roccat-common.c 2011-11-07 19:39:05.364461084 +0100 +1 -3
diff -u -p a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c
@@ -49,12 +49,10 @@ int roccat_common_send(struct usb_device
 	char *buf;
 	int len;
 
-	buf = kmalloc(size, GFP_KERNEL);
+	buf = kmemdup(data, size, GFP_KERNEL);
 	if (buf == NULL)
 		return -ENOMEM;
 
-	memcpy(buf, data, size);
-
 	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
 			HID_REQ_SET_REPORT,
 			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
drivers/hid/hid-roccat-kone.c 2011-11-08 10:45:45.085330572 +0100 renamed from drivers/hid/hid-roccat-kone.c 2011-11-07 19:37:44.826571091 +0100 +1 -3
diff -u -p a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c
@@ -78,12 +78,10 @@ static int kone_send(struct usb_device *
 	char *buf;
 	int len;
 
-	buf = kmalloc(size, GFP_KERNEL);
+	buf = kmemdup(data, size, GFP_KERNEL);
 	if (buf == NULL)
 		return -ENOMEM;
 
-	memcpy(buf, data, size);
-
 	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
 			HID_REQ_SET_REPORT,
 			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
Applied
#1 lore raw
Quoted 30 lines · Thomas Meyer

The semantic patch that makes this change is available in scripts/coccinelle/api/memdup.cocci.

---

diff -u -p a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c

drivers/hid/hid-roccat-common.c 2011-11-08 10:45:42.781966362 +0100 renamed from drivers/hid/hid-roccat-common.c 2011-11-07 19:39:05.364461084 +0100 +1 -3
@@ -49,12 +49,10 @@ int roccat_common_send(struct usb_device
 	char *buf;
 	int len;
 
-	buf = kmalloc(size, GFP_KERNEL);
+	buf = kmemdup(data, size, GFP_KERNEL);
 	if (buf == NULL)
 		return -ENOMEM;
 
-	memcpy(buf, data, size);
-
 	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
 			HID_REQ_SET_REPORT,
 			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,

diff -u -p a/drivers/hid/hid-roccat-kone.c b/drivers/hid/hid-roccat-kone.c

drivers/hid/hid-roccat-kone.c 2011-11-08 10:45:45.085330572 +0100 renamed from drivers/hid/hid-roccat-kone.c 2011-11-07 19:37:44.826571091 +0100 +0 -0
@@ -78,12 +78,10 @@ static int kone_send(struct usb_device *
 	char *buf;
 	int len;
 

drivers/hid/hid-roccat-kone.c 2011-11-08 10:45:45.085330572 +0100 static int kone_send(struct usb_device * · line 87

Quoted 10 lines
drivers/hid/hid-roccat-kone.c 2011-11-08 10:45:45.085330572 +0100 renamed from drivers/hid/hid-roccat-kone.c 2011-11-07 19:37:44.826571091 +0100 +1 -3
-	buf = kmalloc(size, GFP_KERNEL);
+	buf = kmemdup(data, size, GFP_KERNEL);
 	if (buf == NULL)
 		return -ENOMEM;
 
-	memcpy(buf, data, size);
-
 	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
 			HID_REQ_SET_REPORT,
 			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,

Applied, thank you.

Signature · 2 lines
Jiri Kosina
SUSE Labs