linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: Use memdup_user to reuse the code
@ 2015-12-08 11:38 Pathak, Rahul (R.)
  2015-12-08 11:51 ` Dan Carpenter
  0 siblings, 1 reply; 2+ messages in thread
From: Pathak, Rahul (R.) @ 2015-12-08 11:38 UTC (permalink / raw)
  To: gregkh, stern, kborer, dan.carpenter, chasemetzger15
  Cc: linux-usb, linux-kernel

From: Rahul Pathak <rpathak@visteon.com>

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

Signed-off-by: Rahul Pathak <rpathak@visteon.com>
---
 drivers/usb/core/devio.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 38ae877c..05266f0 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1395,11 +1395,9 @@ 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);
 			goto error;
 		}
 		for (totlen = u = 0; u < number_of_packets; u++) {
-- 
1.9.1

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

* Re: [PATCH] usb: Use memdup_user to reuse the code
  2015-12-08 11:38 [PATCH] usb: Use memdup_user to reuse the code Pathak, Rahul (R.)
@ 2015-12-08 11:51 ` Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2015-12-08 11:51 UTC (permalink / raw)
  To: Pathak, Rahul (R.)
  Cc: gregkh, stern, kborer, chasemetzger15, linux-usb, linux-kernel

On Tue, Dec 08, 2015 at 11:38:59AM +0000, Pathak, Rahul (R.) wrote:
> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index 38ae877c..05266f0 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1395,11 +1395,9 @@ 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);
>  			goto error;

This introduces a one err bug.
https://plus.google.com/106378716002406849458/posts/dnanfhQ4mHQ
We can't call kfree(isopkt) when it is an ERR_PTR.

Set it to NULL:

		isopkt = memdup_user(iso_frame_desc, isofrmlen);
		if (IS_ERR(isopkt)) {
			ret = PTR_ERR(isopkt);
			isopkt = NULL;
			goto error;
		}

regards,
dan carpenter


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

end of thread, other threads:[~2015-12-08 12:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-08 11:38 [PATCH] usb: Use memdup_user to reuse the code Pathak, Rahul (R.)
2015-12-08 11:51 ` Dan Carpenter

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).