Skip to contentSkip to conversation

usb: Use memdup_user to reuse the code

PATCH RESEND In review Pathak, Rahul (R.) 2 participants 3 messages Dec 11, 2015 – Jan 4, 2016 USB

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v2 1/1 usb: Use memdup_user to reuse the code

From: Rahul Pathak <[email protected]>

Fixing coccicheck warning which recommends to use memdup_user instead to reimplement its code, using memdup_user simplifies the code

./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user

---

Changes after v1: setting isopkt=NULL for proper kfree() call

---
 drivers/usb/core/devio.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/core/devio.c +4 -5
index 38ae877c..844407c 100644
@@ -1395,11 +1395,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 		number_of_packets = uurb->number_of_packets;
 		isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
 				   number_of_packets;
-		isopkt = kmalloc(isofrmlen, GFP_KERNEL);
-		if (!isopkt)
-			return -ENOMEM;
-		if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
-			ret = -EFAULT;
+		isopkt = memdup_user(iso_frame_desc, isofrmlen);
+		if (IS_ERR(isopkt)) {
+			ret = PTR_ERR(isopkt);
+			isopkt = NULL;
 			goto error;
 		}
 		for (totlen = u = 0; u < number_of_packets; u++) {
Signature · 1 line
1.9.1
#1 lore raw

Hello Greg,

This patch is not yet merged, its already been reviewed and acked by Alan.

Thanks
Rahul

Quoted 40 lines · Rahul Pathak

From: Rahul Pathak <[email protected]>

Fixing coccicheck warning which recommends to use memdup_user instead to reimplement its code, using memdup_user simplifies the code

./drivers/usb/core/devio.c:1398:11-18: WARNING opportunity for memdup_user

---

Changes after v1: setting isopkt=NULL for proper kfree() call

---
 drivers/usb/core/devio.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/usb/core/devio.c +4 -5
index 38ae877c..844407c 100644
@@ -1395,11 +1395,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
 		number_of_packets = uurb->number_of_packets;
 		isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
 				   number_of_packets;
-		isopkt = kmalloc(isofrmlen, GFP_KERNEL);
-		if (!isopkt)
-			return -ENOMEM;
-		if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
-			ret = -EFAULT;
+		isopkt = memdup_user(iso_frame_desc, isofrmlen);
+		if (IS_ERR(isopkt)) {
+			ret = PTR_ERR(isopkt);
+			isopkt = NULL;
 			goto error;
 		}
 		for (totlen = u = 0; u < number_of_packets; u++) {
Signature · 1 line
1.9.1
#2 lore raw
Quoted 4 lines · Rahul (R.)

Hello Greg,

This patch is not yet merged, its already been reviewed and acked by Alan.

Relax. Everyone is on vacation. This stuff is not life or death that it must be done right away.

regards,
dan carpenter